我正在使用pdo连接。我正在尝试运行删除查询,但它在浏览器中显示此消息
*SQLSTATE[HY000]: General error*
这是我的问题:
$user_id = $_POST['user_id']; $result = query($conn, "DELETE FROM user WHERE user_id = '$user_id'");
我不知道为什么会发生这种情况。任何形式的帮助将不胜感激。谢谢
答案 0 :(得分:0)
我认为PHP中不存在查询()函数..它应该是mysql_query或mysqli_query
使用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'");
答案 1 :(得分:0)
根据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);
在查询之前?