[英]Why PDO connection sowing “SQLSTATE[HY000]: General error”?
I am using pdo connection. 我正在使用pdo连接。 I am trying to run a delete query but it is showing this message in the browser 我正在尝试运行删除查询,但它在浏览器中显示此消息
*SQLSTATE[HY000]: General error*
Here is my query: 这是我的查询:
$user_id = $_POST['user_id']; $result = query($conn, "DELETE FROM user WHERE user_id = '$user_id'");
I don't know why happening this. 我不知道为什么会这样。 Any kind of help will be appreciated.Thanks 任何帮助将不胜感激。
I think there is a query() function does not exists in PHP .. It should be mysql_query or mysqli_query 我认为PHP中不存在query()函数。应该是mysql_query或mysqli_query
Using Mysql query is bad because it is depreciated in Updated version of php 使用Mysql查询是不好的,因为它在php的更新版本中已弃用
$result = mysqli_query($conn, "DELETE FROM user WHERE user_id = '$user_id'");
//So using mysqli :)
$result = mysqli_query($conn, "DELETE FROM user WHERE user_id = '$user_id'");
Per MySQL 5.5.35 source code, sql/sql_prepare.cc
: 根据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;
}
It appears that your error (SQL state HY000) will happen when there is a wrong sequence of prepare/execute statements. 似乎当准备/执行语句的顺序错误时,将发生您的错误(SQL状态HY000)。 Double-check our logic to make sure you are properly using prepared statements, eg properly fetching all of the results after the call to query()
before calling it again. 仔细检查我们的逻辑,以确保您正确使用了准备好的语句,例如,在调用query()
之后正确获取所有结果,然后再次调用它。
If you cannot figure it out, isolate the problem to a minimal, complete, and verifiable example ( https://stackoverflow.com/help/mcve ), and post the code here. 如果您无法解决问题,请将问题找出一个最小,完整且可验证的示例( https://stackoverflow.com/help/mcve ),然后在此处发布代码。
UPDATE: 更新:
Does the problem go away (or do you at least get a meaningful error message) if you do 如果您这样做,问题是否消失了(或者您至少得到了有意义的错误消息)
$conn->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
prior to the query? 在查询之前?
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.