Issues

ZF-10866: Zend_Db_Statement->setFetchMode with Zend_Db::FETCH_CLASS and PDO adapter throws exception on newer PHP versions

Description

PHP right now (5.3.3 presents this behaviour, 5.2.14 was not) requires 2 or 3 arguments to function PDOStatement->setFetchMode, which is stated in http://php.net/manual/en/… Unfortunately, Zend_Db_Statement_Pdo's setFetchMode provides only one. This crashes every code that uses setFetchMode with FETCH_CLASS when using PDO. This effectively renders Zend_Db_Select->query() useless, as it calls setFetchMode unconditionally, and probably affects a lot of other methods as well.

Note: Tested with 1.11.1 and 1.8.4 but probably affects everything in between and a lot before 1.8.4.

Priority blocker, because any code using it will refuse to work after PHP upgrade.

Comments

This issue was already reported, but with less background, and was closed with reason not related to original issue.

Hi Ralph,

Seems like a valid Blocker issue on PHP 5.3. Any chance you could implement the fix above, or some kind of passthrough on other methods accepting the fetch mode directly for next minor?

Confirmed. Test Case:


Index: tests/Zend/Db/Statement/Pdo/TestCommon.php
===================================================================
--- tests/Zend/Db/Statement/Pdo/TestCommon.php  (revision 24628)
+++ tests/Zend/Db/Statement/Pdo/TestCommon.php  (working copy)
@@ -120,4 +120,13 @@

     }

+    /**
+     * @group ZF-10866
+     */
+    public function testSetFetchModeClass()
+    {
+        $select = $this->_db->select()->from('zfproducts');
+        $stmt = new Zend_Db_Statement_Pdo($this->_db, $select);
+        $stmt->setFetchMode(PDO::FETCH_CLASS);
+    }
 }

Result:



1) Zend_Db_Statement_Pdo_MysqlTest::testSetFetchModeClass
Zend_Db_Statement_Exception: SQLSTATE[HY000]: General error: fetch mode requires the classname argument

2) Zend_Db_Statement_Pdo_SqliteTest::testSetFetchModeClass
Zend_Db_Statement_Exception: SQLSTATE[HY000]: General error: fetch mode requires the classname argument

Attached possible fix + unit tests. Alters signature of {{Zend_Db_Statement_Pdo::setFetchMode}}, a change which may (?) also need to be made in it's superclass.

I've attached a second patch (ZF-10866_V2.patch) which implements the same functionality without changing the existing method signature. This new implementation is much less code, but doesn't appear to work for PDO::FETCH_INTO (object comes out empty)

Zend_Db does not support using PDO fetch mode constants directly. Please see the reasons stated in @ZF-9728 and ZF-3470.