Re: transactions with php
On 18-Jun-2003 Becoming Digital wrote: ... if(!mysql_query($array[$i])) { $flag = false; break; } after the loop I do if($flag) mysql_query(commit); else mysql_query(rollback); Be careful with that last if() statement. I would either change the script to read '$flag = true' or 'if( isset($flag) )' It's quite possible that I'm mistaken, but I believe that 'if($flag)' would evaluate to false if '$flag = false'. The constant FALSE (or false) will never evaluate as a TRUE condition. if ($flag = true) // this assigns TRUE to $flag and then the // value of $flag will be evaluated. if (isset($flag)) // will evaluate as TRUE because $flag has a value // assigned. It's not NULL. // -- regardless of what the value is. if ($flag) { -- or (assuming $flag is initialized) -- if ($flag === TRUE) { ... so either would be the correct construct here. Regards, -- Don Read [EMAIL PROTECTED] -- It's always darkest before the dawn. So if you are going to steal the neighbor's newspaper, that's the time to do it. (53kr33t w0rdz: sql table query) -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: transactions with php
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. I thought this was fixable now. A while back Monty said that changing users on a connection would reset the connection automatically. He was talking about the next version (which was several versions back of the 4 series). Resetting the connection (according to this theory) would set all the per connection variables to their default and rollback any non-committed transactions. My PHP Mysql extension is a bit hacked up (and I have more to do!), so I can't remember the default now. But I think it should add a 'change user' command when the page ends on any persistent connection. Change to a blank user. So in theory then, web pages would be safe for transactions. A really ugly hack (assuming a Mysql server version as described above) would be (in PHP) to connect persistently to mysql then change the user to a dummy, and then change the user to the one you want again. Doing this at the start of every page should then make it transaction safe. Can someone from MySQL confirm that changing users will reset the connection and rollback unfinished transactions? And starting in what version? -steve- -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
RE: transactions with php
In http://www.mysql.com/doc/en/News-4.0.6.html * mysql_change_user() will now reset the connection to the state of a fresh connect (Ie, ROLLBACK any active transaction, close all temporary tables, reset all user variables etc..) So it is in there, starting with version MySQL 4.0.6. -steve- -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: transactions with php
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]
Re: transactions with php
I found one item in the PHP Classes Repository that may be of use. Unfortunately, the comments are in Spanish, so it's up to you to figure out the code. http://promoxy.mirrors.phpclasses.org/browse.html/file/3077.html Edward Dudlik Becoming Digital www.becomingdigital.com - Original Message - From: Jonas Geiregat [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, 17 June, 2003 13:44 Subject: transactions with php 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 ? -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED] -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: transactions with php
Becoming Digital wrote: I found one item in the PHP Classes Repository that may be of use. Unfortunately, the comments are in Spanish, so it's up to you to figure out the code. http://promoxy.mirrors.phpclasses.org/browse.html/file/3077.html Edward Dudlik Becoming Digital www.becomingdigital.com - Original Message - From: Jonas Geiregat [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, 17 June, 2003 13:44 Subject: transactions with php 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 ? -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED] This is a much better implementation then my previous one I loop trough a array with query's. in the loop I do: if(!mysql_query($array[$i])) { $flag = false; break; } after the loop I do if($flag) mysql_query(commit); else mysql_query(rollback); This should work haven't tested it yet. If anyone got better idea's Post them Regards Jonas Geiregat -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: transactions with php
Becoming Digital wrote: I found one item in the PHP Classes Repository that may be of use. Unfortunately, the comments are in Spanish, so it's up to you to figure out the code. http://promoxy.mirrors.phpclasses.org/browse.html/file/3077.html Edward Dudlik Becoming Digital www.becomingdigital.com - Original Message - From: Jonas Geiregat [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, 17 June, 2003 13:44 Subject: transactions with php 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 ? -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED] This is a much better implementation then my previous one I loop trough a array with query's. in the loop I do: if(!mysql_query($array[$i])) { $flag = false; break; } after the loop I do if($flag) mysql_query(commit); else mysql_query(rollback); This should work haven't tested it yet. If anyone got better idea's Post them Regards Jonas Geiregat -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]
Re: transactions with php
if(!mysql_query($array[$i])) { $flag = false; break; } after the loop I do if($flag) mysql_query(commit); else mysql_query(rollback); Be careful with that last if() statement. I would either change the script to read '$flag = true' or 'if( isset($flag) )' It's quite possible that I'm mistaken, but I believe that 'if($flag)' would evaluate to false if '$flag = false'. Edward Dudlik Becoming Digital www.becomingdigital.com - Original Message - From: Jonas Geiregat [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, 17 June, 2003 15:19 Subject: Re: transactions with php Becoming Digital wrote: I found one item in the PHP Classes Repository that may be of use. Unfortunately, the comments are in Spanish, so it's up to you to figure out the code. http://promoxy.mirrors.phpclasses.org/browse.html/file/3077.html Edward Dudlik Becoming Digital www.becomingdigital.com - Original Message - From: Jonas Geiregat [EMAIL PROTECTED] To: [EMAIL PROTECTED] Sent: Tuesday, 17 June, 2003 13:44 Subject: transactions with php 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 ? -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe: http://lists.mysql.com/[EMAIL PROTECTED] This is a much better implementation then my previous one I loop trough a array with query's. in the loop I do: if(!mysql_query($array[$i])) { $flag = false; break; } after the loop I do if($flag) mysql_query(commit); else mysql_query(rollback); This should work haven't tested it yet. If anyone got better idea's Post them Regards Jonas Geiregat -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED] -- MySQL General Mailing List For list archives: http://lists.mysql.com/mysql To unsubscribe:http://lists.mysql.com/[EMAIL PROTECTED]