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

From: Date: Tue, 25 Feb 2014 13:15:34 +0000
Subject: Bug #65287 [Fbk]: PDOStatement::fetchAll wrong result
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-184415@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:         uw@php.net
 Reported by:        ai at artem dot cc
 Summary:            PDOStatement::fetchAll wrong result
 Status:             Feedback
 Type:               Bug
-Package:            PDO MySQL
+Package:            PDO related
 Operating System:   Centos
 PHP Version:        5.4.17
 Block user comment: N
 Private report:     N

 New Comment:

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.


Previous Comments:
------------------------------------------------------------------------
[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


Thread (7 messages)

« previous php.bugs (#184415) next »