mysqli.php

来自「开源邮件管理系统」· PHP 代码 · 共 1,752 行 · 第 1/5 页

PHP
1,752
字号
            $this->_assignBindColumns($row);        }        if ($fetchmode === MDB2_FETCHMODE_OBJECT) {            $object_class = $this->db->options['fetch_class'];            if ($object_class == 'stdClass') {                $row = (object) $row;            } else {                $row = &new $object_class($row);            }        }        ++$this->rownum;        return $row;    }    // }}}    // {{{ _getColumnNames()    /**     * Retrieve the names of columns returned by the DBMS in a query result.     *     * @return  mixed   Array variable that holds the names of columns as keys     *                  or an MDB2 error on failure.     *                  Some DBMS may not return any columns when the result set     *                  does not contain any rows.     * @access private     */    function _getColumnNames()    {        $columns = array();        $numcols = $this->numCols();        if (PEAR::isError($numcols)) {            return $numcols;        }        for ($column = 0; $column < $numcols; $column++) {            $column_info = @mysqli_fetch_field_direct($this->result, $column);            $columns[$column_info->name] = $column;        }        if ($this->db->options['portability'] & MDB2_PORTABILITY_FIX_CASE) {            $columns = array_change_key_case($columns, $this->db->options['field_case']);        }        return $columns;    }    // }}}    // {{{ numCols()    /**     * Count the number of columns returned by the DBMS in a query result.     *     * @return mixed integer value with the number of columns, a MDB2 error     *                       on failure     * @access public     */    function numCols()    {        $cols = @mysqli_num_fields($this->result);        if (is_null($cols)) {            if ($this->result === false) {                return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,                    'resultset has already been freed', __FUNCTION__);            } elseif (is_null($this->result)) {                return count($this->types);            }            return $this->db->raiseError(null, null, null,                'Could not get column count', __FUNCTION__);        }        return $cols;    }    // }}}    // {{{ nextResult()    /**     * Move the internal result pointer to the next available result     *     * @return true on success, false if there is no more result set or an error object on failure     * @access public     */    function nextResult()    {        $connection = $this->db->getConnection();        if (PEAR::isError($connection)) {            return $connection;        }        if (!@mysqli_more_results($connection)) {            return false;        }        if (!@mysqli_next_result($connection)) {            return false;        }        if (!($this->result = @mysqli_use_result($connection))) {            return false;        }        return MDB2_OK;    }    // }}}    // {{{ free()    /**     * Free the internal resources associated with result.     *     * @return boolean true on success, false if result is invalid     * @access public     */    function free()    {        if (is_object($this->result) && $this->db->connection) {            $free = @mysqli_free_result($this->result);            if ($free === false) {                return $this->db->raiseError(null, null, null,                    'Could not free result', __FUNCTION__);            }        }        $this->result = false;        return MDB2_OK;    }}/** * MDB2 MySQLi buffered result driver * * @package MDB2 * @category Database * @author  Lukas Smith <smith@pooteeweet.org> */class MDB2_BufferedResult_mysqli extends MDB2_Result_mysqli{    // }}}    // {{{ seek()    /**     * Seek to a specific row in a result set     *     * @param int    $rownum    number of the row where the data can be found     * @return mixed MDB2_OK on success, a MDB2 error on failure     * @access public     */    function seek($rownum = 0)    {        if ($this->rownum != ($rownum - 1) && !@mysqli_data_seek($this->result, $rownum)) {            if ($this->result === false) {                return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,                    'resultset has already been freed', __FUNCTION__);            } elseif (is_null($this->result)) {                return MDB2_OK;            }            return $this->db->raiseError(MDB2_ERROR_INVALID, null, null,                'tried to seek to an invalid row number ('.$rownum.')', __FUNCTION__);        }        $this->rownum = $rownum - 1;        return MDB2_OK;    }    // }}}    // {{{ valid()    /**     * Check if the end of the result set has been reached     *     * @return mixed true or false on sucess, a MDB2 error on failure     * @access public     */    function valid()    {        $numrows = $this->numRows();        if (PEAR::isError($numrows)) {            return $numrows;        }        return $this->rownum < ($numrows - 1);    }    // }}}    // {{{ numRows()    /**     * Returns the number of rows in a result object     *     * @return mixed MDB2 Error Object or the number of rows     * @access public     */    function numRows()    {        $rows = @mysqli_num_rows($this->result);        if (is_null($rows)) {            if ($this->result === false) {                return $this->db->raiseError(MDB2_ERROR_NEED_MORE_DATA, null, null,                    'resultset has already been freed', __FUNCTION__);            } elseif (is_null($this->result)) {                return 0;            }            return $this->db->raiseError(null, null, null,                'Could not get row count', __FUNCTION__);        }        return $rows;    }    // }}}    // {{{ nextResult()    /**     * Move the internal result pointer to the next available result     *     * @param a valid result resource     * @return true on success, false if there is no more result set or an error object on failure     * @access public     */    function nextResult()    {        $connection = $this->db->getConnection();        if (PEAR::isError($connection)) {            return $connection;        }        if (!@mysqli_more_results($connection)) {            return false;        }        if (!@mysqli_next_result($connection)) {            return false;        }        if (!($this->result = @mysqli_store_result($connection))) {            return false;        }        return MDB2_OK;    }}/** * MDB2 MySQLi statement driver * * @package MDB2 * @category Database * @author  Lukas Smith <smith@pooteeweet.org> */class MDB2_Statement_mysqli extends MDB2_Statement_Common{    // {{{ _execute()    /**     * Execute a prepared query statement helper method.     *     * @param mixed $result_class string which specifies which result class to use     * @param mixed $result_wrap_class string which specifies which class to wrap results in     * @return mixed a result handle or MDB2_OK on success, a MDB2 error on failure     * @access private     */    function &_execute($result_class = true, $result_wrap_class = false)    {        if (is_null($this->statement)) {            $result =& parent::_execute($result_class, $result_wrap_class);            return $result;        }        $this->db->last_query = $this->query;        $this->db->debug($this->query, 'execute', array('is_manip' => $this->is_manip, 'when' => 'pre', 'parameters' => $this->values));        if ($this->db->getOption('disable_query')) {            $result = $this->is_manip ? 0 : null;            return $result;        }        $connection = $this->db->getConnection();        if (PEAR::isError($connection)) {            return $connection;        }        if (!is_object($this->statement)) {            $query = 'EXECUTE '.$this->statement;        }        if (!empty($this->positions)) {            $parameters = array(0 => $this->statement, 1 => '');            $lobs = array();            $i = 0;            foreach ($this->positions as $parameter) {                if (!array_key_exists($parameter, $this->values)) {                    return $this->db->raiseError(MDB2_ERROR_NOT_FOUND, null, null,                        'Unable to bind to missing placeholder: '.$parameter, __FUNCTION__);                }                $value = $this->values[$parameter];                $type = array_key_exists($parameter, $this->types) ? $this->types[$parameter] : null;                if (!is_object($this->statement)) {                    if (is_resource($value) || $type == 'clob' || $type == 'blob' && $this->db->options['lob_allow_url_include']) {                        if (!is_resource($value) && preg_match('/^(\w+:\/\/)(.*)$/', $value, $match)) {                            if ($match[1] == 'file://') {                                $value = $match[2];                            }                            $value = @fopen($value, 'r');                            $close = true;                        }                        if (is_resource($value)) {                            $data = '';                            while (!@feof($value)) {                                $data.= @fread($value, $this->db->options['lob_buffer_length']);                            }                            if ($close) {                                @fclose($value);                            }                            $value = $data;                        }                    }                    $quoted = $this->db->quote($value, $type);                    if (PEAR::isError($quoted)) {                        return $quoted;                    }                    $param_query = 'SET @'.$parameter.' = '.$quoted;                    $result = $this->db->_doQuery($param_query, true, $connection);                    if (PEAR::isError($result)) {                        return $result;                    }                } else {                    if (is_resource($value) || $type == 'clob' || $type == 'blob') {                        $parameters[] = null;                        $parameters[1].= 'b';                        $lobs[$i] = $parameter;                    } else {                        $quoted = $this->db->quote($value, $type, false);                        if (PEAR::isError($quoted)) {                            return $quoted;                        }                        $parameters[] = $quoted;                        $parameters[1].= $this->db->datatype->mapPrepareDatatype($type);                    }                    ++$i;                }            }            if (!is_object($this->statement)) {                $query.= ' USING @'.implode(', @', array_values($this->positions));            } else {                $result = @call_user_func_array('mysqli_stmt_bind_param', $parameters);                if ($result === false) {                    $err =& $this->db->raiseError(null, null, null,                        'Unable to bind parameters', __FUNCTION__);                    return $err;                }                foreach ($lobs as $i => $parameter) {                    $value = $this->values[$parameter];                    $close = false;                    if (!is_resource($value)) {                        $close = true;                        if (preg_match('/^(\w+:\/\/)(.*)$/', $value, $match)) {                            if ($match[1] == 'file://') {                                $value = $match[2];                            }                            $value = @fopen($value, 'r');                        } else {                            $fp = @tmpfile();     

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?