您好,欢迎来到三六零分类信息网!老站,搜索引擎当天收录,欢迎发信息

PHP pdo 事宜无法回滚

2024/6/11 23:40:21发布31次查看
php pdo 事务无法回滚
public function submit(){
try {
$this->begintransaction();
$this->exec('update people set age=2');
$this->exec('insert into course (course,num) values (数学,100)');
$this->commit();
}catch (exception $e){
$this->rollback();
}
}
这是小弟的事务模块大致如上,数据库引擎为innodb,但不知道为何sql如果执行错误,pdo始终不执行回滚,请高人指定,小弟感激不尽。。。
------解决方案--------------------
不要用try试试,我觉得这里不会抛出异常
php code$this->begintransaction();$this->exec('update people set age=2');//$step1 = mysql_error();//你的类里,改成如果执行sql错误,获取错误代码,相应的函数$this->exec('insert into course (course,num) values (数学,100)');//$step2 = mysql_error();if (!$step1 && !$step2){ $this->commit();}else{ $this->rollback();}
------解决方案--------------------
同意2楼,
两条语句应该只会返回true或false
用if判断就可以了,,不要用 try

该用户其它信息

VIP推荐

免费发布信息,免费发布B2B信息网站平台 - 三六零分类信息网 沪ICP备09012988号-2
企业名录 Product