I really haven't found normal example of PHP file where MySQL transactions are being used. Can you show me simple example of that?
And one more question. I've already done a lot of programming and didn't use transactions. Can I put a PHP function or something in header.php
that if one mysql_query
fails, then the others fail too?
I think I have figured it out, is it right?:
mysql_query("SET AUTOCOMMIT=0");
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");
}
mysql_query("BEGIN");
instead of sequencemysql_query("SET AUTOCOMMIT=0");
mysql_query("START TRANSACTION");
– Stricklanmysql_*
functions in new code. They are no longer maintained and are officially deprecated. See the red box? Learn about prepared statements instead, and use PDO or MySQLi - this article will help you decide which. If you choose PDO, here is a good tutorial. – IlluminanceSET AUTOCOMMIT=0
for BEGIN too. – Zecchinomysql
wun die despite being deprecated, it will be available in PECL forever. – Hibblermysql
– Grandaunt