Bug #66529 [NEW]: PDO::commit returns true on failure
| From: | fk at florian-kaiser dot net | Date: | Tue, 21 Jan 2014 10:16:25 +0000 |
| Subject: | Bug #66529 [NEW]: PDO::commit returns true on failure | ||
| Groups: | php.bugs | ||
| Request: | Send a blank email to php-bugs+get-183931@lists.php.net to get a copy of this message | ||
From: fk at florian-kaiser dot net
Operating system: Debian Linux
PHP version: 5.5.8
Package: PDO Core
Bug Type: Bug
Bug description:PDO::commit returns true on failure
Description:
------------
When you use PDO::beginTransaction(), do a query and issue
PDO::commit(), the result of the last call is bogus at best.
Documentation states "Returns TRUE on success or FALSE on failure.". In
current implementation, this is wrong. In fact, it returns TRUE in all
cases I tested - even for _impossible_ commits. The only time it
actually fails is when issuing a PDO::commit() while no transaction is
active. This will, regardless of what you set PDO::ATTR_ERRMODE to,
result in a PDO::EXCEPTION (that is another bug, see #63546).
Unfortunately, there is another bug in the implementation of
PDO::commit() that makes it almost impossible to detect that error since
"MySQL server has gone away" or "Error reading result set's header" are
only issued as as warnings and neither PDO::errorCode() nor
PDO::errorInfo() are set, nor is a PDOException thrown. PDO_ATTR_ERRMODE
is also not beeing honored. I filed that bug under #66528 and will only
focus on the bug described above in this report.
The easiest way to reproduce is to start a transaction, issue a query,
sleep for a couple of seconds and while doing that, shutting down the
MySQL-Server. When the server is clearly gone, issue PDO::commit().
Although PDO knows it can under no circumstances have commited the data,
it returns success for the operation.
Test script:
---------------
<?php
$dbh = new PDO('mysql:dbname=test;host=127.0.0.1;charset=UTF8',
'testuser', '');
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_SILENT);
// prepare table for test
$dbh->query('DROP TABLE IF EXISTS importantdata');
$dbh->query('create table test.importantdata (a int) engine=innodb');
$dbh->beginTransaction();
$dbh->query('insert into importantdata (a) VALUES (1), (2)');
sleep(20); // shut down mysql-server
var_dump($dbh->commit());
?>
Expected result:
----------------
bool(false)
Actual result:
--------------
bool(true)
--
Edit bug report at https://bugs.php.net/bug.php?id=66529&edit=1
--
Try a snapshot (PHP 5.4): https://bugs.php.net/fix.php?id=66529&r=trysnapshot54
Try a snapshot (PHP 5.5): https://bugs.php.net/fix.php?id=66529&r=trysnapshot55
Try a snapshot (trunk): https://bugs.php.net/fix.php?id=66529&r=trysnapshottrunk
Fixed in SVN: https://bugs.php.net/fix.php?id=66529&r=fixed
Fixed in release: https://bugs.php.net/fix.php?id=66529&r=alreadyfixed
Need backtrace: https://bugs.php.net/fix.php?id=66529&r=needtrace
Need Reproduce Script: https://bugs.php.net/fix.php?id=66529&r=needscript
Try newer version: https://bugs.php.net/fix.php?id=66529&r=oldversion
Not developer issue: https://bugs.php.net/fix.php?id=66529&r=support
Expected behavior: https://bugs.php.net/fix.php?id=66529&r=notwrong
Not enough info: https://bugs.php.net/fix.php?id=66529&r=notenoughinfo
Submitted twice: https://bugs.php.net/fix.php?id=66529&r=submittedtwice
register_globals: https://bugs.php.net/fix.php?id=66529&r=globals
PHP 4 support discontinued: https://bugs.php.net/fix.php?id=66529&r=php4
Daylight Savings: https://bugs.php.net/fix.php?id=66529&r=dst
IIS Stability: https://bugs.php.net/fix.php?id=66529&r=isapi
Install GNU Sed: https://bugs.php.net/fix.php?id=66529&r=gnused
Floating point limitations: https://bugs.php.net/fix.php?id=66529&r=float
No Zend Extensions: https://bugs.php.net/fix.php?id=66529&r=nozend
MySQL Configuration Error: https://bugs.php.net/fix.php?id=66529&r=mysqlcfg