Zend Framework

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

Details

  • Type: Bug Bug
  • Status: Resolved Resolved
  • Priority: N/A N/A
  • Resolution: Won't Fix
  • Affects Version/s: 1.5.2
  • Fix Version/s: 1.9.3
  • Component/s: Zend_Db
  • Labels:
    None

Description

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.

Te reproduce

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

Suggested fix

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());
     }
}

Issue Links

Activity

Hide
Ralph Schindler added a comment -

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:

$stmt->getDriverStatement()->setFetchMode(....); // PDO specific method.

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

Show
Ralph Schindler added a comment - 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:
$stmt->getDriverStatement()->setFetchMode(....); // PDO specific method.
This helps keep the API consistent across all adapters/drivers.
Hide
Waclaw Schiller added a comment -

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.

Show
Waclaw Schiller added a comment - 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.
Hide
Waclaw Schiller added a comment -

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.

Show
Waclaw Schiller added a comment - 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.

People

Vote (1)
Watch (1)

Dates

  • Created:
    Updated:
    Resolved: