Zend_Db_Statement_Mysqli::_execute PHP Method

_execute() public method

Executes a prepared statement.
public _execute ( array $params = null ) : boolean
$params array OPTIONAL Values to bind to parameter placeholders.
return boolean
    public function _execute(array $params = null)
    {
        if (!$this->_stmt) {
            return false;
        }
        // if no params were given as an argument to execute(),
        // then default to the _bindParam array
        if ($params === null) {
            $params = $this->_bindParam;
        }
        // send $params as input parameters to the statement
        if ($params) {
            array_unshift($params, str_repeat('s', count($params)));
            $stmtParams = array();
            foreach ($params as $k => &$value) {
                $stmtParams[$k] =& $value;
            }
            call_user_func_array(array($this->_stmt, 'bind_param'), $stmtParams);
        }
        // execute the statement
        $retval = $this->_stmt->execute();
        if ($retval === false) {
            /**
             * @see Zend_Db_Statement_Mysqli_Exception
             */
            require_once 'Zend/Db/Statement/Mysqli/Exception.php';
            throw new Zend_Db_Statement_Mysqli_Exception("Mysqli statement execute error : " . $this->_stmt->error, $this->_stmt->errno);
        }
        // retain metadata
        if ($this->_meta === null) {
            $this->_meta = $this->_stmt->result_metadata();
            if ($this->_stmt->errno) {
                /**
                 * @see Zend_Db_Statement_Mysqli_Exception
                 */
                require_once 'Zend/Db/Statement/Mysqli/Exception.php';
                throw new Zend_Db_Statement_Mysqli_Exception("Mysqli statement metadata error: " . $this->_stmt->error, $this->_stmt->errno);
            }
        }
        // statements that have no result set do not return metadata
        if ($this->_meta !== false) {
            // get the column names that will result
            $this->_keys = array();
            foreach ($this->_meta->fetch_fields() as $col) {
                $this->_keys[] = $this->_adapter->foldCase($col->name);
            }
            // set up a binding space for result variables
            $this->_values = array_fill(0, count($this->_keys), null);
            // set up references to the result binding space.
            // just passing $this->_values in the call_user_func_array()
            // below won't work, you need references.
            $refs = array();
            foreach ($this->_values as $i => &$f) {
                $refs[$i] =& $f;
            }
            $this->_stmt->store_result();
            // bind to the result variables
            call_user_func_array(array($this->_stmt, 'bind_result'), $this->_values);
        }
        return $retval;
    }