lunes, 9 de febrero de 2015

PHP MySQL rollBack transacciones try catch

$db = new PDO($dsn,$user,$password);
$db->beginTransaction();

try{
  //first execution      
  $db->exec("delete from mytable");

  //second execution
  $db->exec("insert into anothertable");

  //if all went well
  $db->commit();

} catch (Exception $e) {

  //something broke, hit undo
  $db->rollBack();

}
 
 
 
. 

No hay comentarios: