ZF-3470: Zend_Db_Statement_Pdo::setFetchMode does only except one parameter, while for PDO::FETCH_CLASS 2 (or 3) are needed

Issue Type: Bug Created: 2008-06-17T10:40:40.000+0000 Last Updated: 2010-12-23T13:57:42.000+0000 Status: Resolved Fix version(s): - 1.9.3 (22/Sep/09)

Reporter: S. Koopal (stien) Assignee: Ralph Schindler (ralph) Tags: - Zend_Db

Related issues: - ZF-10866



For Zend_Db_Statement_Pdo::setFetchMode multiple arguments could be required, when working with PDO::FETCH_CLASS for example. The current implementation does not support this feature since only the fetchmode can be set.

h3. Te reproduce

<pre class="highlight">
class FooClass {} 

$stmt = $db->query ( 'SELECT * FROM foo' );
$stmt->setFetchMode ( PDO::FETCH_CLASS, 'FooClass' );

Which results in: Zend_Db_Statement_Exception: SQLSTATE[HY000]: General error: No fetch class specified in ...

h3. Suggested fix

<pre class="highlight">
public function setFetchMode($mode)
     $args = func_get_args ();  

     $this->_fetchMode = $mode;

     try {
          return call_user_func_array ( array ( $this->_stmt, 'setFetchMode' ), $args );
     } catch (PDOException $e) {
          require_once 'Zend/Db/Statement/Exception.php';
          throw new Zend_Db_Statement_Exception($e->getMessage());


Posted by Ralph Schindler (ralph) on 2009-08-27T14:53:47.000+0000

Instead of adding PDO specific features to the Statement general API, we have decided to add a method called getDriverStatement() which will be able to return the internal statement handler.

In the case of PDO, it will return PDOStatement, and you'll be able to call setFetchMode() on that object:

<pre class="highlight">
$stmt->getDriverStatement()->setFetchMode(....); // PDO specific method.

This helps keep the API consistent across all adapters/drivers.

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

This won't work. Zend_Db_Select has method query. This method accepts parameter $fetchMode, which if not given is initialized to Zend_Db_Adapter_Abstract->getFetchMode(). Later, setFetchMode is called with this parameter. Point is, if we use PDO, which REQUIRES 2 or 3 arguments to setFetchMode, this will break no matter what fetch mode is set beforehand.

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

Sorry, previous comment was not specific enough. PDO with FETCH_CLASS requires 2 or 3 arguments to setFetchMode. Still, PDO and $fetchMode==FETCH_CLASS will break, no matter if fetchMode was added with getDriverStatement or not.

Have you found an issue?

See the Overview section for more details.


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

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