I set up the transaction mechanism and deliberately set the second sql statement to be wrong. Why was the first sql statement executed in the end? Shouldn't the transaction be rolled back and not executed at all?
陈老师
陈老师 2018-05-19 12:55:01
0
1
1198


<?php

$pdo=new PDO('mysql:host=localhost;dbname=student','root','root');

try{

$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

$pdo->beginTransaction();

//The first sql statement

$sqla="delete from chen where id=14";

$pdo->exec($sqla) ;

//The sql statement on the second day

$sqlb="delete froms chen where id=15"; //The from is written incorrectly on purpose

$pdo->exec($sqlb);


}catch(Exception $e){

$pdo ->rollBack();

$e->getMessage();

echo "Operation failed";

}

?>


陈老师
陈老师

reply all(1)
NULL

Is the database engine MyISAM? Try changing it to InnoDB

  • reply Yes, I found the problem. Thank you very much. Awesome.
    陈老师 author 2018-05-21 10:55:46
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template