I'm trying to read from DB using mysqli but the script is crashing on the mysqli_stmt_bind_result
statement. I cannot find any reason - perhaps any of you with fresh eyes??
If I comment out that line, $rows is populated, so it's clearly connecting to the database OK.
<?php
error_reporting(E_ALL);
ini_set('display_errors', '1');
$id="a";
$name="b";
$dbc=mysqli_connect("1.2.3.4", "username", "password", "database") OR die ('Could not connect to MySQL: ' . mysqli_connect_error() );
echo "Hello\n";
#### Read park names from DB ####
$q="SELECT id,name FROM park WHERE status=? ORDER BY id";
$stmt=mysqli_prepare($dbc, $q);
$status='show';
mysqli_stmt_bind_param($stmt,'s',$status);
mysqli_stmt_execute($stmt);
mysqli_stmt_bind_result($stmt,$id,$name);
mysqli_stmt_store_result($stmt);
$rows=mysqli_stmt_num_rows($stmt);
echo "rows: $rows\n";
while (mysqli_stmt_fetch($stmt)) {
echo "<li><a href=\"/park/$id/\">$name</a></li>\n";
}
mysqli_stmt_close($stmt);
#### Finished reading park names from DB ####
mysqli_close($dbc);
echo "Goodbye\n";
?>
PHPINFO reports the following for mysqli:
Client API library version 5.0.91
Client API header version 5.0.95
I've tried switching between PHP 5.2 and 5.4, no change.