我一直在努力解決這個問題一段時間,併到處搜索答案。 Post:Example of how to use bind_result vs get_result給出了一個非常好的解釋,說明如何使用兩種不同的方法來檢索已執行預備語句的結果。這也符合我發現的其他答案。我有PHP版本5.6.15所以對於get_result()這也不應該是一個問題(只能從> 5.3)。準備語句檢索結果:爲什麼bind_result()工作和get_result()不工作?
我有一個面向對象的編程環境,但爲了測試一個條帶化的例子,以最少的程序從數據庫中選擇一行來查找錯誤。
結果:我的版本與 「bind_result()」 的作品完美,回報:
和 「get_result()」 版的回報:
"Call to a member function fetch_assoc() on boolean in ...".
我嘗試了很多的變化,以得到它的工作,但它回到了以下最低應該工作,但它不。有人可以幫忙嗎?
我在數據庫中的測試表有兩列:「id」和「content」。 )
<!DOCTYPE html>
<html lang="en">
<?php
static $connection;
$config = parse_ini_file('../config.ini');
$connection = new mysqli('localhost',$config['username'],$config['password'],$config['dbname']);
$query = "SELECT * FROM test WHERE id = ?";
$id = 1;
$stmt = $connection->prepare($query);
$stmt->bind_param('i',$id);
$stmt->execute();
$stmt->store_result();
$stmt->bind_result($id, $content);
while ($stmt->fetch()) {
echo 'ID: '.$id.'<br>';
echo 'Content: '.$content.'<br>';
}
$stmt->free_result();
$stmt->close();
$connection->close();
?>
</html>
所以版本get_result(不工作:
工作與bind_result版本()
<!DOCTYPE html>
<html lang="en">
<?php
static $connection;
$config = parse_ini_file('../config.ini');
$connection = new mysqli('localhost',$config['username'],$config['password'],$config['dbname']);
$query = "SELECT * FROM test WHERE id = ?";
$id = 1;
$stmt = $connection->prepare($query);
$stmt->bind_param('i',$id);
$stmt->execute();
$stmt->store_result();
$result = $stmt->get_result();
while ($row = $result->fetch_assoc()) {
echo 'ID: '.$row['id'].'<br>';
echo 'Content: '.$row['content'].'<br>';
}
$stmt->free_result();
$stmt->close();
$connection->close();
?>
</html>
你在get_result()函數中給出了什麼參數? –
檢查你的'phpinfo()'看看你是否安裝了mysqli擴展的mysqlnd驅動程序 – frosty
@frosty:下一個我從phpinfo()獲得:php version = 5.6.15 在configure命令中:'--with-庫MySQLi = mysqlnd」 配置 - MySQL的: - 客戶端API庫版本:mysqlnd 5.0.11-dev的 - 20120503 配置-mysqlnd: - 版本:mysqlnd 5.0.11-dev的 - 20120503點 - 加載的插件:mysqlnd,debug_trace, auth_plugin_mysql_native_password,auth_plugin_mysql_clear_password,auth_plugin_sha256_password - API擴展:mysqli,mysql,pdo_mysql。似乎沒問題!? – Monique