【发布时间】:2014-03-12 05:01:10
【问题描述】:
我在 try/catch 块中有三个 sql 查询。自动提交已关闭,所有三个查询都运行没有错误,我已经验证了(如果任何查询失败,它不应该到达提交行,但我已经通过 xdebug 验证了它,一次单步执行代码)。当代码到达 commit() 函数调用时,mysqli 返回 false,但没有错误消息。当之前的查询都有效时,提交怎么会失败?
这基本上是代码的样子:
try{
$mysqli->autocommit(false);
$sql1 = "insert into...";
$mysqli->query($sql); // Works!
if($mysqli->error)
{
$mysqli->rollback();
throw new Exception....
}
$sql2 = "insert into...";
$mysqli->query($sql); // Works!
if($mysqli->error)
{
$mysqli->rollback();
throw new Exception....
}
$mysqli->commit(); // Fail
}
【问题讨论】:
-
而且受影响的表的存储类型是innoDB吧?
-
$mysqli->autocommit(false)成功了吗?尝试提交后$mysqli->error是什么? -
表是innoDB,是的。自动提交有效。 $mysqli-error 为空,没有错误信息,没有错误代码,什么都没有。