Home >Backend Development >PHP Tutorial >PHP pdo transaction rollback code example_PHP tutorial
PHP pdo transaction rollback code example
$this->beginTransaction();
$this->exec('update people set age=2');
//$step1 = mysql tutorial_error();//In your class, change it to if there is an error in executing sql, get the error code, and the corresponding function
$this->exec('INSERT INTO course (course,num) VALUES ("Mathematics",100)');
//$step2 = mysql_error();
if (!$step1 && !$step2)
{
$this->commit();
}
else
{
$this->rollBack();
}