From: Operating system: Fedora Rawhide PHP version: 5.3.6 Package: PDO related Bug Type: Bug Bug description:DBLIB segfaults when GROUPing with 0 rows for prepared statements
Description: ------------ I haven't fully figured out the cause of this problem, but for what I can narrow it down, it's a bit of a remote case. What I am experiencing is odd behavior when doing a PDO(DBLIB) prepared statement on a SELECT query with a GROUP BY clause. As far as I can tell, when the query would have returned 0 results, the query returns an empty array, but the next time the query is run, I get the following result (regardless of what the data should actually be): array(1) { [0]=> array(2) { ["!"]=> NULL [0]=> NULL } } After this occurs, any attempt (whether explicit or implicit) to unset the statement results in a segfault in Zend/zend_alloc.c:2028: if (ZEND_MM_IS_FREE_BLOCK(next_block)) { I have also found that this only happens when the first execution of the prepared statement results in a 0 row query. If the order of the execution in the test script below is reversed so that a result is returned, the prepared statement works fine from then on. Another specific of this bug is that it only occurs with the GROUP BY clause. The query will work fine if I have an aggregate function, but do not have the GROUP BY column specified. I have tried the query in a different query tool, and it works fine. I also tried the script with the php5.3-201105231230 snapshot, but was still having the issue. This problem is similar to Bug #40639, but my problem seems more narrow in focus. I also do not receive the same segfault as the other bug. Test script: --------------- <?php $db = new PDO('dblib:host=server;dbname=db', 'user', 'pass'); $query = $db->prepare('SELECT COALESCE(SUM(tblTransaction.Amount), 0) FROM tblTransaction INNER JOIN tblDiscount ON tblTransaction.TransactionTypeID = tblDiscount.TransactionTypeID AND tblDiscount.DiscountID = :DiscountID WHERE tblTransaction.Voided IS NULL AND tblTransaction.RegistrationID = :RegistrationID GROUP BY tblTransaction.RegistrationID'); // This combination does not exist together in the database $execute = $query->execute(array(':DiscountID' => 1, ':RegistrationID' => 114)); echo "\nExecuted: " . ($execute ? 'Successful' : 'Failed') . "\n"; $results = $query->fetchAll(); var_dump($results); // This combination does exist together in the database $execute = $query->execute(array(':DiscountID' => 20, ':RegistrationID' => 114)); echo 'Executed: ' . ($execute ? 'Successful' : 'Failed') . "\n"; $results = $query->fetchAll(); var_dump($results); unset($query); echo 'Unset'; Expected result: ---------------- Executed: Successful array(0) { } Executed: Successful array(1) { [0]=> array(2) { ["computed"]=> string(4) "5.00" [0]=> string(4) "5.00" } } Unset Actual result: -------------- Executed: Successful array(0) { } Executed: Successful array(1) { [0]=> array(2) { ["!"]=> NULL [0]=> NULL } } Segmentation fault (core dumped) -- Edit bug report at http://bugs.php.net/bug.php?id=54908&edit=1 -- Try a snapshot (PHP 5.2): http://bugs.php.net/fix.php?id=54908&r=trysnapshot52 Try a snapshot (PHP 5.3): http://bugs.php.net/fix.php?id=54908&r=trysnapshot53 Try a snapshot (trunk): http://bugs.php.net/fix.php?id=54908&r=trysnapshottrunk Fixed in SVN: http://bugs.php.net/fix.php?id=54908&r=fixed Fixed in SVN and need be documented: http://bugs.php.net/fix.php?id=54908&r=needdocs Fixed in release: http://bugs.php.net/fix.php?id=54908&r=alreadyfixed Need backtrace: http://bugs.php.net/fix.php?id=54908&r=needtrace Need Reproduce Script: http://bugs.php.net/fix.php?id=54908&r=needscript Try newer version: http://bugs.php.net/fix.php?id=54908&r=oldversion Not developer issue: http://bugs.php.net/fix.php?id=54908&r=support Expected behavior: http://bugs.php.net/fix.php?id=54908&r=notwrong Not enough info: http://bugs.php.net/fix.php?id=54908&r=notenoughinfo Submitted twice: http://bugs.php.net/fix.php?id=54908&r=submittedtwice register_globals: http://bugs.php.net/fix.php?id=54908&r=globals PHP 4 support discontinued: http://bugs.php.net/fix.php?id=54908&r=php4 Daylight Savings: http://bugs.php.net/fix.php?id=54908&r=dst IIS Stability: http://bugs.php.net/fix.php?id=54908&r=isapi Install GNU Sed: http://bugs.php.net/fix.php?id=54908&r=gnused Floating point limitations: http://bugs.php.net/fix.php?id=54908&r=float No Zend Extensions: http://bugs.php.net/fix.php?id=54908&r=nozend MySQL Configuration Error: http://bugs.php.net/fix.php?id=54908&r=mysqlcfg