0

I can't seem to be able to place the resultset into an array and then use print_r to print out the array. Here's the script:

<?php

require( 'wp-load.php' );

$local = 'xxx';
$user  = 'xxx'; 
$pass  = 'xxx';
$data  = 'xxx';

$testConnection  = mysqli_connect($local,$user,$pass, $data); 


if (!$testConnection) {
die('Error: ' . mysqli_connect_errno() . PHP_EOL);
}
echo 'Database connection working!';


global $wpdb;
$result = $wpdb->get_results ( "SELECT * FROM $wpdb->options" );


/* this is commented out but works 

foreach ( $result as $row )   {
echo $row->option_id.'<br>';
}   
*/  

//PART NOT WORKING    

$results = [];
while($row = mysqli_fetch_array($result,MYSQLI_NUM))
{
    echo "hello";  //never executes?????
    $results[] = $row;

}

//$results has all that you need
print_r($results);  //empty array??? 




 $testClosed = mysqli_close($testConnection);



 if ($testClosed) {
     echo "closed";
 }


?>
DCR
  • 14,737
  • 12
  • 52
  • 115

1 Answers1

0

while($row = mysqli_fetch_array($result,MYSQLI_NUM))
{
    echo "hello";  //never executes?????
    $results[] = $row;
}

Try removing the while statement out of there. Array is going to be given to you with mysqli_fetch_array . So just write it like this :

 $row = mysqli_fetch_array($result,MYSQLI_NUM);
 $results[] = $row;

You could just access the indexes with $row[...] but still, up to you.

On the other hand :

On the documentation for the function there is such statement : Return Value: Returns an array of strings that corresponds to the fetched row. NULL if there are no more rows in result-set . So you might be calling a invalid table from your DB.

Can Oezlemis
  • 169
  • 1
  • 10