我正在尝试通过以下方式从我的数据库中检索最近的日期:
$stmt2 = $conn->prepare("SELECT reportDate FROM reports WHERE bot=? ORDER BY reportDate DESC LIMIT ?");
$limit = 1;
$stmt2->bind_param("ii", $id, $limit);
$stmt2->execute();
$stmt2->bind_result($lastSeen);
我得到错误:
PHP Fatal error: Call to a member function bind_param() on a non-object
我知道这通常发生在 SQL 语句中存在语法错误时,但我已经尝试在 phpmyadmin 中运行它并且它非常有效。有什么建议吗?
最佳答案
LIMIT 通常不会从准备好的语句中获取任何参数,因此您的 prepare
失败。这就是为什么您会在下次调用时看到该错误。
也通过How to apply bindValue method in LIMIT clause?和 LIMIT keyword on MySQL with prepared statement
关于php - Mysqli 准备好的语句在 SQL 中工作但不在我的应用程序中,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/29347996/