Details
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
| This issue is duplicated by: | ||||
| ZF-10866 | Zend_Db_Statement->setFetchMode with Zend_Db::FETCH_CLASS and PDO adapter throws exception on newer PHP versions |
|
|
|
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.
$stmt->getDriverStatement()->setFetchMode(....); // PDO specific method.