I use this code to insert data in 2 tables,
try {
array(PDO::ATTR_PERSISTENT => true);
$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$db->beginTransaction();
// 1st insert
$db->exec("insert into users (id, username, password,permission) values (18, 'raman', 2002,3)");
//2nd insert
$db->exec("insert into table_11 (id,user_id1,amount) values (14, '130', '11300')");
$db->commit();
} catch (Exception $e) {
$db->rollBack();
echo "Failed : " . $e->getMessage();
}
This code work fine however when i test the transaction by make 2nd insert error as i changed table name to wrong table name, i found 1st insert still work and able to add new data even 2nd insert not work, My question why 1st insert worked ? I use MySQL.