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

📄 odbc.php

📁 FP2 CRM code+Mysql DB
💻 PHP
📖 第 1 页 / 共 2 页
字号:
            return $this->odbcRaiseError(DB_ERROR_UNSUPPORTED);        }        if ($nrows === false) {            return $this->odbcRaiseError();        }        return $nrows;    }    // }}}    // {{{ quoteIdentifier()    /**     * Quotes a string so it can be safely used as a table or column name     *     * 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     *     * @see DB_common::quoteIdentifier()     * @since Method available since Release 1.6.0     */    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);    }    // }}}    // {{{ 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.     *               A DB_Error object on failure.     *     * @see DB_common::nextID(), DB_common::getSequenceName(),     *      DB_odbc::createSequence(), DB_odbc::dropSequence()     */    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 on failure.     *     * @see DB_common::createSequence(), DB_common::getSequenceName(),     *      DB_odbc::nextID(), DB_odbc::dropSequence()     */    function createSequence($seq_name)    {        return $this->query('CREATE TABLE '                            . $this->getSequenceName($seq_name)                            . ' (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.  A DB_Error object on failure.     *     * @see DB_common::dropSequence(), DB_common::getSequenceName(),     *      DB_odbc::nextID(), DB_odbc::createSequence()     */    function dropSequence($seq_name)    {        return $this->query('DROP TABLE ' . $this->getSequenceName($seq_name));    }    // }}}    // {{{ autoCommit()    /**     * Enables or disables automatic commits     *     * @param bool $onoff  true turns it on, false turns it off     *     * @return int  DB_OK on success.  A DB_Error object if the driver     *               doesn't support auto-committing transactions.     */    function autoCommit($onoff = false)    {        if (!@odbc_autocommit($this->connection, $onoff)) {            return $this->odbcRaiseError();        }        return DB_OK;    }    // }}}    // {{{ commit()    /**     * Commits the current transaction     *     * @return int  DB_OK on success.  A DB_Error object on failure.     */    function commit()    {        if (!@odbc_commit($this->connection)) {            return $this->odbcRaiseError();        }        return DB_OK;    }    // }}}    // {{{ rollback()    /**     * Reverts the current transaction     *     * @return int  DB_OK on success.  A DB_Error object on failure.     */    function rollback()    {        if (!@odbc_rollback($this->connection)) {            return $this->odbcRaiseError();        }        return DB_OK;    }    // }}}    // {{{ odbcRaiseError()    /**     * Produces a DB_Error object regarding the current problem     *     * @param int $errno  if the error is being manually raised pass a     *                     DB_ERROR* constant here.  If this isn't passed     *                     the error information gathered from the DBMS.     *     * @return object  the DB_Error object     *     * @see DB_common::raiseError(),     *      DB_odbc::errorNative(), DB_common::errorCode()     */    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;                    }                    $native_code = odbc_error($this->connection);                    // S1000 is for "General Error."  Let's be more specific.                    if ($native_code == 'S1000') {                        $errormsg = odbc_errormsg($this->connection);                        static $error_regexps;                        if (!isset($error_regexps)) {                            $error_regexps = array(                                '/includes related records.$/i'  => DB_ERROR_CONSTRAINT,                                '/cannot contain a Null value/i' => DB_ERROR_CONSTRAINT_NOT_NULL,                            );                        }                        foreach ($error_regexps as $regexp => $code) {                            if (preg_match($regexp, $errormsg)) {                                return $this->raiseError($code,                                        null, null, null,                                        $native_code . ' ' . $errormsg);                            }                        }                        $errno = DB_ERROR;                    } else {                        $errno = $this->errorCode($native_code);                    }                    break;                default:                    $errno = $this->errorCode(odbc_error($this->connection));            }        }        return $this->raiseError($errno, null, null, null,                                 $this->errorNative());    }    // }}}    // {{{ errorNative()    /**     * Gets the DBMS' native error code and message produced by the last query     *     * @return string  the DBMS' error code and message     */    function errorNative()    {        if (!is_resource($this->connection)) {            return @odbc_error() . ' ' . @odbc_errormsg();        }        return @odbc_error($this->connection) . ' ' . @odbc_errormsg($this->connection);    }    // }}}    // {{{ tableInfo()    /**     * Returns information about a table or a result set     *     * @param object|string  $result  DB_result object from a query or a     *                                 string containing the name of a table.     *                                 While this also accepts a query result     *                                 resource identifier, this behavior is     *                                 deprecated.     * @param int            $mode    a valid tableInfo mode     *     * @return array  an associative array with the information requested.     *                 A DB_Error object on failure.     *     * @see DB_common::tableInfo()     * @since Method available since Release 1.7.0     */    function tableInfo($result, $mode = null)    {        if (is_string($result)) {            /*             * Probably received a table name.             * Create a result resource identifier.             */            $id = @odbc_exec($this->connection, "SELECT * FROM $result");            if (!$id) {                return $this->odbcRaiseError();            }            $got_string = true;        } elseif (isset($result->result)) {            /*             * Probably received a result object.             * Extract the result resource identifier.             */            $id = $result->result;            $got_string = false;        } else {            /*             * Probably received a result resource identifier.             * Copy it.             * Deprecated.  Here for compatibility only.             */            $id = $result;            $got_string = false;        }        if (!is_resource($id)) {            return $this->odbcRaiseError(DB_ERROR_NEED_MORE_DATA);        }        if ($this->options['portability'] & DB_PORTABILITY_LOWERCASE) {            $case_func = 'strtolower';        } else {            $case_func = 'strval';        }        $count = @odbc_num_fields($id);        $res   = array();        if ($mode) {            $res['num_fields'] = $count;        }        for ($i = 0; $i < $count; $i++) {            $col = $i + 1;            $res[$i] = array(                'table' => $got_string ? $case_func($result) : '',                'name'  => $case_func(@odbc_field_name($id, $col)),                'type'  => @odbc_field_type($id, $col),                'len'   => @odbc_field_len($id, $col),                'flags' => '',            );            if ($mode & DB_TABLEINFO_ORDER) {                $res['order'][$res[$i]['name']] = $i;            }            if ($mode & DB_TABLEINFO_ORDERTABLE) {                $res['ordertable'][$res[$i]['table']][$res[$i]['name']] = $i;            }        }        // free the result only if we were called on a table        if ($got_string) {            @odbc_free_result($id);        }        return $res;    }    // }}}    // {{{ getSpecialQuery()    /**     * Obtains the query string needed for listing a given type of objects     *     * Thanks to symbol1@gmail.com and Philippe.Jausions@11abacus.com.     *     * @param string $type  the kind of objects you want to retrieve     *     * @return string  the list of objects requested     *     * @access protected     * @see DB_common::getListOf()     * @since Method available since Release 1.7.0     */    function getSpecialQuery($type)    {        switch ($type) {            case 'databases':                if (!function_exists('odbc_data_source')) {                    return null;                }                $res = @odbc_data_source($this->connection, SQL_FETCH_FIRST);                if (is_array($res)) {                    $out = array($res['server']);                    while($res = @odbc_data_source($this->connection,                                                   SQL_FETCH_NEXT))                    {                        $out[] = $res['server'];                    }                    return $out;                } else {                    return $this->odbcRaiseError();                }                break;            case 'tables':            case 'schema.tables':                $keep = 'TABLE';                break;            case 'views':                $keep = 'VIEW';                break;            default:                return null;        }        /*         * Removing non-conforming items in the while loop rather than         * in the odbc_tables() call because some backends choke on this:         *     odbc_tables($this->connection, '', '', '', 'TABLE')         */        $res  = @odbc_tables($this->connection);        if (!$res) {            return $this->odbcRaiseError();        }        $out = array();        while ($row = odbc_fetch_array($res)) {            if ($row['TABLE_TYPE'] != $keep) {                continue;            }            if ($type == 'schema.tables') {                $out[] = $row['TABLE_SCHEM'] . '.' . $row['TABLE_NAME'];            } else {                $out[] = $row['TABLE_NAME'];            }        }        return $out;    }    // }}}}/* * Local variables: * tab-width: 4 * c-basic-offset: 4 * End: */?>

⌨️ 快捷键说明

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