At 10:44 -0700 6/17/03, Jonas Geiregat wrote:
I'm trying to implement transaction (mysql) in my php code. Could anyone tell me if this is a good way of using them. I make an array with all the query's I loop through them. like this mysql_query($qarray[$i])or die($flag = false);. After the loop I do if($flag) commit; else rollback;
Is this a good way of implementing them ?

die() will terminate your script, so you will not ever actually get a chance to roll back.

If you're using a non-persistent connection, PHP will close the
connection when the script terminates, and the MySQL server will roll back
implicitly.  For a non-persistent connection, the connection remains open
and you may not see the rollback behavior your expect.

If you're looping through the statements, why not set the flag if any
of them fail and exit the loop immediately?  Then commit or roll back
depending on the value of the flag at the end of the loop.


-- Paul DuBois, Senior Technical Writer Madison, Wisconsin, USA MySQL AB, www.mysql.com

Are you MySQL certified? http://www.mysql.com/certification/


-- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED]



Reply via email to