我真的很困惑....我正在尝试使用mysqli从数据库读取,但脚本正在崩溃mysqli_stmt_bind_result语句。我找不到任何理由 - 也许你们中有人有新鲜的眼睛?
如果我注释掉该行,则会填充$ rows,因此它显然连接到数据库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报告了以下mysqli:
客户端API库版本5.0.91
客户端API标头版本5.0.95
我尝试在PHP 5.2和5.4之间切换,没有变化。真的卡住了想法 - 任何想法都感激不尽!
谢谢,
杰里米