Bug #81286 [Com]: PDO return phantom rowset and no error when MYSQL_ATTR_USE_BUFFERED_QUERY=FALSE

From: Date: Sat, 24 Jul 2021 21:04:08 +0000
Subject: Bug #81286 [Com]: PDO return phantom rowset and no error when MYSQL_ATTR_USE_BUFFERED_QUERY=FALSE
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-235320@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=81286&edit=1 ID: 81286 Comment by: tropicano at ukr dot net Reported by: tropicano at ukr dot net Summary: PDO return phantom rowset and no error when MYSQL_ATTR_USE_BUFFERED_QUERY=FALSE Status: Verified Type: Bug Package: PDO MySQL Operating System: All PHP Version: 7.4.21 Block user comment: N Private report: N New Comment: Ok, then another query like this: $qr = $db->query('SELECT SELECT'); why returns FALSE and error info ? What different? Subject query and this second query both with errors. But subject query return PDOStatement and second query return FALSE. I think in this case both PDO::query() must return same result - FALSE or PDOStatement with errors. Previous Comments: ------------------------------------------------------------------------ [2021-07-24 20:45:25] dharman@php.net PDO::query() does not fetch a result in unbuffered mode. Therefore, you should not get an error when you call PDO::query(). You would get an error if you tried to fetch the results or close the statement. The problem is that it should close the previous result when fetching the next result in the same statement, which PDO_MySQL doesn't do, hence this bug report. So PDO::query() should not give you an error, but PDOStatement::nextRowset() should. ------------------------------------------------------------------------ [2021-07-24 20:31:05] tropicano at ukr dot net I think, if first SQL statement do error then PDO::query() may return FALSE, but you said it will return PDOStatement with phantom result? ------------------------------------------------------------------------ [2021-07-24 20:13:35] dharman@php.net Thanks for reporting this issue. This has already been fixed in PHP 8.0.1 but the fix was not backported to PHP 7. It might be possible to backport it... FYI, your expected result doesn't match what really should happen. The proper output with SILENT mode enabled should be: Array ( [0] => 00000 [1] => [2] => ) Array ( [0] => 00000 [1] => [2] => ) Array ( [0] => 21000 [1] => 1242 [2] => Subquery returns more than 1 row ) ------------------------------------------------------------------------ [2021-07-24 12:30:27] tropicano at ukr dot net Description: ------------ Unexpected phantom rowset and no error when PDO::MYSQL_ATTR_USE_BUFFERED_QUERY = FALSE. When PDO::MYSQL_ATTR_USE_BUFFERED_QUERY = TRUE then result expected. Test script: --------------- $db = new PDO("mysql:host=$db_host;dbname=$db_name", $db_user, $db_pass, [PDO::MYSQL_ATTR_USE_BUFFERED_QUERY => FALSE]); $qr = $db->query('SELECT IF(1, (SELECT 1 UNION ALL SELECT 2), 0)'); print_r($db->errorInfo()); // here is no error if ($qr) { print_r($qr->errorInfo()); // here is no error too $qr->nextRowset(); // return false; print_r($qr->errorInfo()); // here is no error again } Expected result: ---------------- Array ( [0] => 21000 [1] => 1242 [2] => Subquery returns more than 1 row ) Actual result: -------------- Array ( [0] => 00000 [1] => [2] => ) Array ( [0] => 00000 [1] => [2] => ) Array ( [0] => 00000 [1] => [2] => ) ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=81286&edit=1

« previous php.bugs (#235320) next »