]> granicus.if.org Git - php/commitdiff
MFB: Fixed bug #43139 PDO ignores ATTR_DEFAULT_FETCH_MODE in some cases with
authorIlia Alshanetsky <iliaa@php.net>
Wed, 31 Oct 2007 12:58:24 +0000 (12:58 +0000)
committerIlia Alshanetsky <iliaa@php.net>
Wed, 31 Oct 2007 12:58:24 +0000 (12:58 +0000)
fetchAll()

NEWS
ext/pdo/pdo_stmt.c
ext/pdo/tests/bug_43139.phpt [new file with mode: 0644]

diff --git a/NEWS b/NEWS
index a3542e7bcabd8509a7e9f34d329cd89a02f07365..0fc67a7707631e7f2ac837bf53b9f8bc48a0f886 100644 (file)
--- a/NEWS
+++ b/NEWS
@@ -40,6 +40,8 @@ PHP                                                                        NEWS
 - Fixed htmlentities/htmlspecialchars not to accept partial multibyte
   sequences. (Stas)
 
+- Fixed bug #43139 (PDO ignores ATTR_DEFAULT_FETCH_MODE in some cases with
+  fetchAll()). (Ilia)
 - Fixed bug #43130 (Bound parameters cannot have - in their name). (Ilia)
 - Fixed bug #43099 (XMLWriter::endElement() does not check # of params).
   (Ilia)
index 7b9482098676b146f828cd7ca4216c618560c59e..2cc242875504b4db4493ca4414fd6376e20f77fa 100755 (executable)
@@ -1546,6 +1546,10 @@ static PHP_METHOD(PDOStatement, fetchAll)
                }
        }
 
+       if ((how & ~PDO_FETCH_FLAGS) == PDO_FETCH_USE_DEFAULT) {
+               how |= stmt->default_fetch_type & ~PDO_FETCH_FLAGS;
+       }
+
        if (!error)     {
                PDO_STMT_CLEAR_ERR();
                MAKE_STD_ZVAL(data);
diff --git a/ext/pdo/tests/bug_43139.phpt b/ext/pdo/tests/bug_43139.phpt
new file mode 100644 (file)
index 0000000..04b9bf3
--- /dev/null
@@ -0,0 +1,34 @@
+--TEST--
+PDO Common: Bug #43139 (PDO ignore ATTR_DEFAULT_FETCH_MODE in some cases with fetchAll())
+--SKIPIF--
+<?php # vim:ft=php
+if (!extension_loaded('pdo')) die('skip');
+$dir = getenv('REDIR_TEST_DIR');
+if (false == $dir) die('skip no driver');
+require_once $dir . 'pdo_test.inc';
+PDOTest::skip();
+?>
+--FILE--
+<?php
+if (getenv('REDIR_TEST_DIR') === false) putenv('REDIR_TEST_DIR='.dirname(__FILE__) . '/../../pdo/tests/');
+require_once getenv('REDIR_TEST_DIR') . 'pdo_test.inc';
+$db = PDOTest::factory();
+
+$db->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
+$db->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_WARNING);
+
+var_dump($db->query('select 0 as abc, 1 as xyz, 2 as def')->fetchAll(PDO::FETCH_GROUP));
+?>
+--EXPECT--
+array(1) {
+  [0]=>
+  array(1) {
+    [0]=>
+    array(2) {
+      ["xyz"]=>
+      string(1) "1"
+      ["def"]=>
+      string(1) "2"
+    }
+  }
+}