⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 odbc.php

📁 太烦了
💻 PHP
📖 第 1 页 / 共 2 页
字号:
    // {{{ numCols()    function numCols($result)    {        $cols = @odbc_num_fields($result);        if (!$cols) {            return $this->odbcRaiseError();        }        return $cols;    }    // }}}    // {{{ affectedRows()    /**     * Returns the number of rows affected by a manipulative query     * (INSERT, DELETE, UPDATE)     * @return mixed int affected rows, 0 when non manip queries or     *               DB error on error     */    function affectedRows()    {        if (empty($this->manip_result)) {  // In case of SELECT stms            return 0;        }        $nrows = @odbc_num_rows($this->manip_result);        if ($nrows == -1) {            return $this->odbcRaiseError();        }        return $nrows;    }    // }}}    // {{{ numRows()    /**     * ODBC may or may not support counting rows in the result set of     * SELECTs.     *     * @param $result the odbc result resource     * @return the number of rows, or 0     */    function numRows($result)    {        $nrows = @odbc_num_rows($result);        if ($nrows == -1) {            return $this->odbcRaiseError(DB_ERROR_UNSUPPORTED);        }        return $nrows;    }    // }}}    // {{{ quoteIdentifier()    /**     * Quote a string so it can be safely used as a table / column name     *     * Quoting style depends on which dbsyntax was passed in the DSN.     *     * Use 'mssql' as the dbsyntax in the DB DSN only if you've unchecked     * "Use ANSI quoted identifiers" when setting up the ODBC data source.     *     * @param string $str  identifier name to be quoted     *     * @return string  quoted identifier string     *     * @since 1.6.0     * @access public     */    function quoteIdentifier($str)    {        switch ($this->dsn['dbsyntax']) {            case 'access':                return '[' . $str . ']';            case 'mssql':            case 'sybase':                return '[' . str_replace(']', ']]', $str) . ']';            case 'mysql':            case 'mysqli':                return '`' . $str . '`';            default:                return '"' . str_replace('"', '""', $str) . '"';        }    }    // }}}    // {{{ quote()    /**     * @deprecated  Deprecated in release 1.6.0     * @internal     */    function quote($str) {        return $this->quoteSmart($str);    }    // }}}    // {{{ errorNative()    /**     * Get the native error code of the last error (if any) that     * occured on the current connection.     *     * @access public     *     * @return int ODBC error code     */    function errorNative()    {        if (!isset($this->connection) || !is_resource($this->connection)) {            return @odbc_error() . ' ' . @odbc_errormsg();        }        return @odbc_error($this->connection) . ' ' . @odbc_errormsg($this->connection);    }    // }}}    // {{{ nextId()    /**     * Returns the next free id in a sequence     *     * @param string  $seq_name  name of the sequence     * @param boolean $ondemand  when true, the seqence is automatically     *                           created if it does not exist     *     * @return int  the next id number in the sequence.  DB_Error if problem.     *     * @internal     * @see DB_common::nextID()     * @access public     */    function nextId($seq_name, $ondemand = true)    {        $seqname = $this->getSequenceName($seq_name);        $repeat = 0;        do {            $this->pushErrorHandling(PEAR_ERROR_RETURN);            $result = $this->query("update ${seqname} set id = id + 1");            $this->popErrorHandling();            if ($ondemand && DB::isError($result) &&                $result->getCode() == DB_ERROR_NOSUCHTABLE) {                $repeat = 1;                $this->pushErrorHandling(PEAR_ERROR_RETURN);                $result = $this->createSequence($seq_name);                $this->popErrorHandling();                if (DB::isError($result)) {                    return $this->raiseError($result);                }                $result = $this->query("insert into ${seqname} (id) values(0)");            } else {                $repeat = 0;            }        } while ($repeat);        if (DB::isError($result)) {            return $this->raiseError($result);        }        $result = $this->query("select id from ${seqname}");        if (DB::isError($result)) {            return $result;        }        $row = $result->fetchRow(DB_FETCHMODE_ORDERED);        if (DB::isError($row || !$row)) {            return $row;        }        return $row[0];    }    /**     * Creates a new sequence     *     * @param string $seq_name  name of the new sequence     *     * @return int  DB_OK on success.  A DB_Error object is returned if     *              problems arise.     *     * @internal     * @see DB_common::createSequence()     * @access public     */    function createSequence($seq_name)    {        $seqname = $this->getSequenceName($seq_name);        return $this->query("CREATE TABLE ${seqname} ".                            '(id integer NOT NULL,'.                            ' PRIMARY KEY(id))');    }    // }}}    // {{{ dropSequence()    /**     * Deletes a sequence     *     * @param string $seq_name  name of the sequence to be deleted     *     * @return int  DB_OK on success.  DB_Error if problems.     *     * @internal     * @see DB_common::dropSequence()     * @access public     */    function dropSequence($seq_name)    {        $seqname = $this->getSequenceName($seq_name);        return $this->query("DROP TABLE ${seqname}");    }    // }}}    // {{{ autoCommit()    function autoCommit($onoff = false)    {        if (!@odbc_autocommit($this->connection, $onoff)) {            return $this->odbcRaiseError();        }        return DB_OK;    }    // }}}    // {{{ commit()    function commit()    {        if (!@odbc_commit($this->connection)) {            return $this->odbcRaiseError();        }        return DB_OK;    }    // }}}    // {{{ rollback()    function rollback()    {        if (!@odbc_rollback($this->connection)) {            return $this->odbcRaiseError();        }        return DB_OK;    }    // }}}    // {{{ odbcRaiseError()    /**     * Gather information about an error, then use that info to create a     * DB error object and finally return that object.     *     * @param  integer  $errno  PEAR error number (usually a DB constant) if     *                          manually raising an error     * @return object  DB error object     * @see errorNative()     * @see DB_common::errorCode()     * @see DB_common::raiseError()     */    function odbcRaiseError($errno = null)    {        if ($errno === null) {            switch ($this->dbsyntax) {                case 'access':                    if ($this->options['portability'] & DB_PORTABILITY_ERRORS) {                        $this->errorcode_map['07001'] = DB_ERROR_NOSUCHFIELD;                    } else {                        // Doing this in case mode changes during runtime.                        $this->errorcode_map['07001'] = DB_ERROR_MISMATCH;                    }            }            $errno = $this->errorCode(odbc_error($this->connection));        }        return $this->raiseError($errno, null, null, null,                        $this->errorNative());    }    // }}}}/* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: */?>

⌨️ 快捷键说明

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