0

Newbie in MySQL.

I have been reading about transaction...

do transactions have to be written in the database itself? Or, can you write it in the PHP?

I found this:

mysql_query("START TRANSACTION");

$a1 = mysql_query("INSERT INTO rarara (l_id) VALUES('1')");
$a2 = mysql_query("INSERT INTO rarara (l_id) VALUES('2')");

if ($a1 and $a2) {
    mysql_query("COMMIT");
} else {        
    mysql_query("ROLLBACK");
}

But, is this enough by itslef? Or does the above only work WITH something that's already written in the database?

i.e. - does the above code invoke something the the MySQL DB or is the code above the transaction itself??

Thanks

yolo191919
  • 11
  • 2

0 Answers0