MySQL 事务回滚

php

function rollbackoriginal1() {
    $conn = mysql_connect('127.0.0.1', 'root', 'root') or die('DB connection failed!');
    mysql_select_db('test', $conn);
    mysql_query('set names "UTF8"');
    mysql_query('BEGIN');
    $sql1 = "INSERT INTO `foo`(`id`,`name`) VALUES(17,111);";
    $sql2 = "INSERT INTO `foo_copy`(`id`,`name`) VALUES(17,111);";
    $res1 = mysql_query($sql1);
    $res2 = mysql_query($sql2);
    var_dump($sql1);
    var_dump($sql2);
    var_dump($res1);
    var_dump($res2);
    if ($res1 && $res2) {
        mysql_query('COMMIT');
        var_dump('commit success!');
    } else {
        mysql_query('ROLLBACK');
        var_dump('commit failed, rollback!');
    }
    mysql_query('END');
}

rollbackoriginal1();

 

转载于:https://www.cnblogs.com/blts/p/11051144.html

你可能感兴趣的:(MySQL 事务回滚)