|
php.net | support | documentation | report a bug | advanced search | search howto | statistics | random bug | login |
[2013-07-18 14:14 UTC] 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)
}
PatchesPull RequestsHistoryAllCommentsChangesGit/SVN commits
|
|||||||||||||||||||||||||||||||||||||
Copyright © 2001-2025 The PHP GroupAll rights reserved. |
Last updated: Thu Oct 23 07:00:01 2025 UTC |
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.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.