note 97499 added to mysqli.autocommit
| From: | Matt at osu1 dot php dot net | Date: | Fri, 23 Apr 2010 02:47:08 +0000 |
| Subject: | note 97499 added to mysqli.autocommit | ||
| Groups: | php.notes | ||
| Request: | Send a blank email to php-notes+get-168533@lists.php.net to get a copy of this message | ||
A note for anyone concerned about the post by Glen on Mar 11 2007. I've tested mysqli
transactions forcing a runtime error before the commit and the issue he describes (future requests
hanging until restarting apache).
In my testing I redeclared a function before the commit to cause a runtime fatal error. When the
error was hit, a rollback was successfully performed automatically. The changes were never committed
to the database and did not hang forever in a pending state as he seems to have experienced.
Try it for yourself, example:
<?php
$mysqli->autocommit( false );
$mysqli->query( "INSERT INTO table SET col = val" );
$mysqli->query( "INSERT INTO table SET col = val" );
$mysqli->query( "INSERT INTO table SET col = val" );
echo 'Made it this far.'
// Force a runtime error.
function a(){}
function a(){}
echo 'Even further.'
$mysqli->commit();
?>
This will output 'Made it this far.' and then error out and the changes will automatically
be rolled back by MySQL. If you run it again without the function a(){}, it runs fine and the
changes commit correctly.
This issue seems to be resolved based on my testing of Apache 2.0.63 / PHP 5.3.2 / MySQL 5.1.44.
----
Server IP: 192.41.40.227
Probable Submitter: 65.255.201.218
----
Manual Page -- http://www.php.net/manual/en/mysqli.autocommit.php
Edit -- https://master.php.net/note/edit/97499
Del: integrated -- https://master.php.net/note/delete/97499/integrated
Del: useless -- https://master.php.net/note/delete/97499/useless
Del: bad code -- https://master.php.net/note/delete/97499/bad+code
Del: spam -- https://master.php.net/note/delete/97499/spam
Del: non-english -- https://master.php.net/note/delete/97499/non-english
Del: in docs -- https://master.php.net/note/delete/97499/in+docs
Del: other reasons-- https://master.php.net/note/delete/97499
Reject -- https://master.php.net/note/reject/97499
Search -- https://master.php.net/manage/user-notes.php