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

Issue Type: Bug Created: 2010-12-23T13:53:32.000+0000 Last Updated: 2012-05-17T18:25:07.000+0000 Status: Closed Fix version(s): Reporter: Waclaw Schiller (torinthiel) Assignee: Adam Lundrigan (adamlundrigan) Tags: - Zend_Db

  • zf-crteam-padraic
  • zf-crteam-priority
  • zf-crteam-review

Related issues: - ZF-9728

Attachments: - ZF-10866.patch


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… 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.


Posted by Waclaw Schiller (torinthiel) on 2010-12-23T13:57:12.000+0000

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

Posted by Pádraic Brady (padraic) on 2011-08-28T09:51:30.000+0000

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?

Posted by Adam Lundrigan (adamlundrigan) on 2012-02-24T00:47:22.000+0000

Confirmed. Test Case:

<pre class="highlight">
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);
+    }


<pre class="highlight">

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

Posted by Adam Lundrigan (adamlundrigan) on 2012-02-24T01:16:16.000+0000

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.

Posted by Adam Lundrigan (adamlundrigan) on 2012-02-24T03:04:11.000+0000

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)

Posted by Adam Lundrigan (adamlundrigan) on 2012-05-17T18:25:07.000+0000

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

Have you found an issue?

See the Overview section for more details.


© 2006-2018 by Zend, a Rogue Wave Company. Made with by awesome contributors.

This website is built using zend-expressive and it runs on PHP 7.