在我的本地/开发环境中,MySQLi查询执行正常.但是,当我在我的Web主机环境中上传它时,我收到此错误:
致命错误:在...中的非对象上调用成员函数bind_param()
这是代码:
global $mysqli;
$stmt = $mysqli->prepare("SELECT id, description FROM tbl_page_answer_category WHERE cur_own_id = ?");
$stmt->bind_param('i', $cur_id);
$stmt->execute();
$stmt->bind_result($uid, $desc);
Run Code Online (Sandbox Code Playgroud)
为了检查我的查询,我试图通过控制面板phpMyAdmin执行查询,结果是OK.
我对 MySQL 相当陌生,所以如果这听起来像一个愚蠢的问题,我深表歉意。
当我学习 sql 安全性和防止 sql 注入时,我了解到在为这样的 id 获取结果时使用 bindparam 更好:
//Prepare Statement
$stmt = $mysqli->prepare("SELECT * FROM my_table WHERE id=?");
if ( false===$stmt ) {
die('prepare() failed: ' . htmlspecialchars($mysqli->error));
}
$rc = $stmt->bind_param("i", $id);
if ( false===$rc ) {
die('bind_param() failed: ' . htmlspecialchars($stmt->error));
}
$rc = $stmt->execute();
if ( false===$rc ) {
die('execute() failed: ' . htmlspecialchars($stmt->error));
}
// Get the data result from the query. You need to bind results for each column that is …Run Code Online (Sandbox Code Playgroud)