我可以安全地忽略错误代码为 00000 的 MySQL 错误 HY000
我已经将 PHP (5.2) 与 PDO (MySQL 5.1) 设置为在发生错误时抛出异常:
$pdo = new PDO(...);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
现在,我有时会收到一个异常,只告诉我“HY000:一般错误”。我试图从 PDO 中获取更多信息,但我只能说:
- errorInfo():
array(0 => 'HY000')
- errorCode():
array( 0 => '00000')
失败的查询如下所示:
INSERT INTO user_values
SELECT user_id,
attribute_id,
?,
value
FROM user_values
WHERE user_id = ?
AND set_id = ?
我已确保所有游标均已正确关闭 ($stmt->closeCursor()
)。在我的语句上调用 fetchAll()
时会引发异常。经过一番搜索后,我发现有些人只是忽略了这个错误,但忽略 PDO 异常似乎是完全错误的。
该怎么办?我是否必须检查“这是一个插入,没有结果集,所以忽略这些异常”(因为我没有单独的插入、选择、更新等方法)。
I've set up PHP (5.2) with PDO (MySQL 5.1) to throw exceptions when an error occurs:
$pdo = new PDO(...);
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
Now, I get sometimes an exception that only tells me "HY000: General error". I've tried to get more info out of PDO, but all I can say is that:
- errorInfo():
array(0 => 'HY000')
- errorCode():
array(0 => '00000')
The query that fails looks like this:
INSERT INTO user_values
SELECT user_id,
attribute_id,
?,
value
FROM user_values
WHERE user_id = ?
AND set_id = ?
I've ensured that all cursors are properly closed ($stmt->closeCursor()
). The exception is thrown when calling fetchAll()
on my statement. After some searching around I found that some are just ignoring this error, but it seems just plain wrong to dismiss a PDO exception.
What to do? Do I have to check like "It's an INSERT, there is no result set so ignore those exception" (as I don't have separate methods for INSERT, SELECT, UPDATE, ...).
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
错误代码 00000 表示成功(或者更确切地说没有发现错误)。
error code 00000 means successful (or rather no error found).