PHP回滚方法失败了

时间:2015-05-27 05:57:37

标签: php mysql rollback

我试过这段代码,遗憾的是回滚方法失败了! 提前谢谢!!

$bash = new mysqli('localhost', 'root', '','dbastegoi');
$bash->autocommit(FALSE);

echo 'timologio';
$r =$bash->query("INSERT INTO tbparastatika (strArithmos, fkERGO, strPROMITH, sngCOST, intTYPOS, intDRASH) VALUES ('1','1001','123123123',800138,1,1)");
//ΕΙΣΑΓΩΓΗ ΤΙΜΟΛΟΓΙΟΥ
 $i = $bash->insert_id;
ECHO PHP_EOL;
echo 'dapanh';
try {
    $r =$bash->query("INSERT INTO tbdapanes_stegash (idPARASTATnIKO, sngCOST, fkDIAMERISMA, intMONTH) VALUES ($i,100,1,1)");
    echo $r;
} catch (Exception $e) {
    echo 'error2';
}

$bash->commit();
$bash->rollback();

//$SYNDESH->commit();
//$SYNDESH->rollback();
$bash->close();

1 个答案:

答案 0 :(得分:0)

你不能先提交一个提交然后再提交一个roolback。如果查询运行没有错误,则必须进行提交;如果出现错误,则必须进行回滚:

try {
    $r =$bash->query("INSERT INTO tbdapanes_stegash (idPARASTATnIKO, sngCOST, fkDIAMERISMA, intMONTH) VALUES ($i,100,1,1)");
    echo $r;
    $bash->commit();
} catch (Exception $e) {
    echo 'error2';
    $bash->rollback();
}