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始终不执行回滚,请高人指定,小弟感激不尽

解决方案 »

  1.   

    不要用try试试,我觉得这里不会抛出异常$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.   

    同意2楼,
    两条语句应该只会返回true或false用if判断就可以了,,不要用 try
      

  3.   

    public function submit(){
    try {
    $this->beginTransaction();
    $this->exec('update people set age=2');
    $this->exec('INSERT_error INTO course (course,num) VALUES ("数学",100)');
    $this->commit();
    }catch (Exception $e){
    $this->rollBack();
    }
    }
    补充问题:
    INSERT_error INTO course (course,num) VALUES ("数学",100)
    如上,如果我把第二条sql改成错误的拼写也不会抛出异常吗?
      

  4.   


    知道了,innoDB引擎才支持回退~~~