Bug #65287 [Opn]: PDOStatement::fetchAll wrong result

From: Date: Mon, 24 Apr 2017 20:15:16 +0000
Subject: Bug #65287 [Opn]: PDOStatement::fetchAll wrong result
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-208764@lists.php.net to get a copy of this message
Edit report at https://bugs.php.net/bug.php?id=65287&edit=1 ID: 65287 Updated by: adambaratz@php.net Reported by: ai at artem dot cc Summary: PDOStatement::fetchAll wrong result Status: Open Type: Bug -Package: PDO related +Package: PDO MySQL Operating System: Centos PHP Version: 5.6.16 Block user comment: N Private report: N New Comment: Moving back to the PDO MySQL package based on Matteo's feedback. Previous Comments: ------------------------------------------------------------------------ [2015-11-27 07:50:44] mbeccati@php.net I've been able to replicate the issue on PHP 5.6, only when PDO_mysql is using mysqlnd. For completeness, I've also tried PDO_pgsql, which is working just fine. Even if the test table has two different int records (4 and 5), I get: array(1) { [""]=> int(5) } The PHP-7.0 or master branches do not seem to be affected. ------------------------------------------------------------------------ [2014-02-25 14:30:58] ai at artem dot cc Hi. The problem appears in fetchAll method with PDO::FETCH_COLUMN | PDO::FETCH_UNIQUE, 0 as arguments. Try fetch results from any table with fetchAll(PDO::FETCH_COLUMN | PDO::FETCH_UNIQUE, 0)) ------------------------------------------------------------------------ [2014-02-25 13:15:34] uw@php.net nixnutz@linux-dstv:~/src/php-src> grep -i -R stringi ext/pdo_*/*.c nixnutz@linux-dstv:~/src/php-src> grep -i -R fetch_unique ext/pdo_*/*.c AFAIK all this conversion stuff is core not driver stuff. ------------------------------------------------------------------------ [2014-02-25 13:09:37] uw@php.net How would one support something for which there is not even any documentation... Apart from that it just works fine for me... $db = new PDO( "mysql:host=127.0.0.1;port=3311;dbname=test", "root", "", array( PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION, PDO::ATTR_EMULATE_PREPARES => false, PDO::ATTR_STRINGIFY_FETCHES => true, PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC ) ); $stmt = $db->query("SELECT 1, 1.23"); var_dump($stmt->fetchAll()); $db->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, false); $stmt = $db->query("SELECT 1, 1.23"); var_dump($stmt->fetchAll()); array(1) { [0]=> array(2) { [1]=> string(1) "1" ["1.23"]=> string(4) "1.23" } } array(1) { [0]=> array(2) { [1]=> int(1) ["1.23"]=> string(4) "1.23" } } Please, provide a proper case that can be reproduced. Fetching results from an unknown table 'test' cannot be reproduced and verified. ------------------------------------------------------------------------ [2013-07-18 14:14:22] ai at artem dot cc Description: ------------ When the mysqlnd driver is used PDOStatement->fetchAll(PDO::FETCH_COLUMN | PDO::FETCH_UNIQUE, 0) does not return proper results when PDO::ATTR_STRINGIFY_FETCHES and PDO::ATTR_EMULATE_PREPARES set to 0 Test script: --------------- $pdo = new PDO('mysql:host=127.0.0.1;dbname=test', 'root', '123'); $pdo->setAttribute(PDO::ATTR_STRINGIFY_FETCHES, 0); $pdo->setAttribute(PDO::ATTR_EMULATE_PREPARES, 0); var_dump($pdo->query("SELECT id FROM test")->fetchAll(PDO::FETCH_COLUMN | PDO::FETCH_UNIQUE, 0)); Expected result: ---------------- array(2) { [1]=> int(1) [2]=> int(2) } Actual result: -------------- array(1) { [""]=> int(2) } ------------------------------------------------------------------------ -- Edit this bug report at https://bugs.php.net/bug.php?id=65287&edit=1

« previous php.bugs (#208764) next »