ZF-1440: Binding parameters and results to PHP variables is broken
Description
The function bindParam(), bindValue(), and bindColumn() need some bugfixing. These are not working with any Zend_Db adapters currently.
The function bindParam(), bindValue(), and bindColumn() need some bugfixing. These are not working with any Zend_Db adapters currently.
Comments
Posted by Jeffrey Sambells (jeffrey) on 2007-05-29T12:10:04.000+0000
From my testing this seems to be an issue with PDO and the way the execute wrapper is defined:
<? /** * Executes a prepared statement. * * @param array $params OPTIONAL Values to bind to parameter placeholders. * @return bool * @throws Zend_Db_Statement_Exception */ public function execute(array $params = array()) { try { return $this->_stmt->execute($params); } catch (PDOException $e) { require_once 'Zend/Db/Statement/Exception.php'; throw new Zend_Db_Statement_Exception($e->getMessage()); } } ?>if you execute the object without any parameters to the Zend execute method:
$stmt->execute()
$params is assigned an empty array. PDO them seems to use this empty array rather than the parameters from bindParam etc. if you change the function declaration to:
public function execute(array $params = null)
everything begins to work again as without an input it now passes NULL to the PDO execute method rather than an empty array.
Posted by Jeffrey Sambells (jeffrey) on 2007-05-29T12:25:19.000+0000
Also, the default NULL values for $type in bindValue() (and possibly others) is also causing issues:
public function bindValue($parameter, $value, $type = null)
If you bind a value without specifying the $type with a PDO::PARAM_* value then the value becomes null when executed.
I suggest changing it to:
public function bindValue($parameter, $value, $type = null) { if (is_string($parameter) && $parameter[0] != ':') { $parameter = ":$parameter"; } try { if(is_null($type)) { return $this->_stmt->bindValue($parameter, $value); } return $this->_stmt->bindValue($parameter, $value, $type); } catch (PDOException $e) { require_once 'Zend/Db/Statement/Exception.php'; throw new Zend_Db_Statement_Exception($e->getMessage()); } }
Posted by Bill Karwin (bkarwin) on 2007-05-29T13:36:35.000+0000
Thanks for the help debugging, Jeffrey! That did it -- at least for PDO adapters.
The fixes you suggest have been committed in revision 5048.
I'm going to leave this issue open for now, because I'd like to get it working across all adapters.
Posted by Bill Karwin (bkarwin) on 2007-06-08T20:58:41.000+0000
This fix was included in 1.0.0 RC2, at least for PDO adapters.
I have opened ZF-1475, ZF-1476, ZF-1477 for these binding features in IBM DB2, Oracle, and Mysqli.
Posted by Bill Karwin (bkarwin) on 2007-06-08T20:59:04.000+0000
Link to ZF-1475.
Posted by Bill Karwin (bkarwin) on 2007-06-08T20:59:18.000+0000
Link to ZF-1476.
Posted by Bill Karwin (bkarwin) on 2007-06-08T20:59:30.000+0000
Link to ZF-1477.