php - Mysqli 准备好的语句在 SQL 中工作但不在我的应用程序中

标签 php mysql web mysqli prepared-statement

我正在尝试通过以下方式从我的数据库中检索最近的日期:

$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/

相关文章:

PHP MySql 在 codeigniter 中嵌套子查询。未找到数据库?

php - 简写做类似 : if($variable == 1 || $variable == "whatever" || $variable == '492' ) . 的事情

mysql - 如何通过一条MySQL查询查询夫妻数据?

php - "Unknown column in ' 字段列表 '"当准备语句的占位符在子查询中

python - Django 单复选框调查问卷

php - 当它的值类似于 1 :00 PM? 时,如何在 Mysql 数据库 sql 中获取大于或等于的值

mysql - 数组关联和数据库设计

javascript - 语义 UI 侧边栏不会显示 - React

javascript - Meteor.js 应用程序无法启动 | "You are attempting to run Meteor as the ' root' super 用户...”

javascript - 在 Web 应用程序中实现灰盒