每 MySQL 5.5.35 源代码,sql/sql_prepare.cc:
bool
Reprepare_observer::report_error(THD *thd)
{
/*
This 'error' is purely internal to the server:
- No exception handler is invoked,
- No condition is added in the condition area (warn_list).
The diagnostics area is set to an error status to enforce
that this thread execution stops and returns to the caller,
backtracking all the way to Prepared_statement::execute_loop().
*/
thd->stmt_da->set_error_status(thd, ER_NEED_REPREPARE,
ER(ER_NEED_REPREPARE), "HY000");
m_invalidated= TRUE;
return TRUE;
}
当准备/执行语句的顺序错误时,您的错误(SQL 状态 HY000)似乎会发生。仔细检查我们的逻辑以确保您正确使用准备好的语句,例如在再次调用 query() 之后正确获取所有结果。
如果您无法弄清楚,请将问题隔离为一个最小、完整且可验证的示例 (https://stackoverflow.com/help/mcve),然后在此处发布代码。
更新:
如果你这样做了,问题会消失吗(或者你至少会得到一个有意义的错误消息)
$conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
在查询之前?