oci8.php

来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· PHP 代码 · 共 1,694 行 · 第 1/5 页

PHP
1,694
字号
<?php // +----------------------------------------------------------------------+// | PHP Version 4                                                        |// +----------------------------------------------------------------------+// | Copyright (c) 1998-2004 Manuel Lemos, Tomas V.V.Cox,                 |// | Stig. S. Bakken, Lukas Smith                                         |// | All rights reserved.                                                 |// +----------------------------------------------------------------------+// | MDB is a merge of PEAR DB and Metabases that provides a unified DB   |// | API as well as database abstraction for PHP applications.            |// | This LICENSE is in the BSD license style.                            |// |                                                                      |// | Redistribution and use in source and binary forms, with or without   |// | modification, are permitted provided that the following conditions   |// | are met:                                                             |// |                                                                      |// | Redistributions of source code must retain the above copyright       |// | notice, this list of conditions and the following disclaimer.        |// |                                                                      |// | Redistributions in binary form must reproduce the above copyright    |// | notice, this list of conditions and the following disclaimer in the  |// | documentation and/or other materials provided with the distribution. |// |                                                                      |// | Neither the name of Manuel Lemos, Tomas V.V.Cox, Stig. S. Bakken,    |// | Lukas Smith nor the names of his contributors may be used to endorse |// | or promote products derived from this software without specific prior|// | written permission.                                                  |// |                                                                      |// | THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS  |// | "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT    |// | LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS    |// | FOR A PARTICULAR PURPOSE ARE DISCLAIMED.  IN NO EVENT SHALL THE      |// | REGENTS OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT,          |// | INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, |// | BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS|// |  OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED  |// | AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT          |// | LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY|// | WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE          |// | POSSIBILITY OF SUCH DAMAGE.                                          |// +----------------------------------------------------------------------+// | Author: Lukas Smith <smith@backendmedia.com>                         |// +----------------------------------------------------------------------+// $Id: oci8.php,v 1.21.4.24 2004/03/31 16:02:40 lsmith Exp $require_once('MDB/Common.php');/** * MDB OCI8 driver * * Notes: * - when fetching in associative mode all keys are uppercased which is not the *   intenteded behavior. Due to BC issues this will not be changed in MDB 1.x *   however. * * - createDatabase and dropDatabase are not supported * * - Text fields with unspecified length limit are created as VARCHAR with an *   optional limit that may not exceed 4000 characters. * * - date fields are emulated with date fields with time set to 00:00:00.     time fields are emulated with date fields with the day set to 0001-01-01. * * - The numRows method is emulated by fetching all the rows into memory. *   Avoid using it if for queries with large result sets. * * - Oracle does not provide direct support for returning result sets restricted     to a given range. Such support is emulated in the MDB oci8 driver. * * - Storing data in large object fields has to be done in two phases: first the     fields are initialized using a INSERT or UPDATE query that sets the fields     to an empty value, then the data values are uploaded to the large objects     returned by reference from the executed queries. *   Besides the fact that only INSERT and UPDATE queries are supported to     upload large object data values, only UPDATE queries that affect only one     row will set the large object fields correctly. * * - The driver alterTable method does not implement table or column renaming. * * @package MDB * @category Database * @author Lukas Smith <smith@backendmedia.com>  */class MDB_oci8 extends MDB_Common {    var $connection = 0;    var $connected_user;    var $connected_password;    var $escape_quotes = "'";    var $uncommitedqueries = 0;    var $results = array();    var $current_row = array();    var $columns = array();    var $rows = array();    var $limits = array();    var $row_buffer = array();    var $highest_fetched_row = array();    // {{{ constructor    /**     * Constructor     */    function MDB_oci8()    {        $this->MDB_Common();        $this->phptype = 'oci8';        $this->dbsyntax = 'oci8';                $this->supported['Sequences'] = 1;        $this->supported['Indexes'] = 1;        $this->supported['SummaryFunctions'] = 1;        $this->supported['OrderByText'] = 1;        $this->supported['CurrId'] = 1;        $this->supported["AffectedRows"]= 1;        $this->supported['Transactions'] = 1;        $this->supported['SelectRowRanges'] = 1;        $this->supported['LOBs'] = 1;        $this->supported['Replace'] = 1;        $this->supported['SubSelects'] = 1;                $this->options['DBAUser'] = FALSE;        $this->options['DBAPassword'] = FALSE;                $this->errorcode_map = array(            1 => MDB_ERROR_CONSTRAINT,            900 => MDB_ERROR_SYNTAX,            904 => MDB_ERROR_NOSUCHFIELD,            921 => MDB_ERROR_SYNTAX,            923 => MDB_ERROR_SYNTAX,            942 => MDB_ERROR_NOSUCHTABLE,            955 => MDB_ERROR_ALREADY_EXISTS,            1400 => MDB_ERROR_CONSTRAINT_NOT_NULL,            1407 => MDB_ERROR_CONSTRAINT_NOT_NULL,            1476 => MDB_ERROR_DIVZERO,            1722 => MDB_ERROR_INVALID_NUMBER,            2289 => MDB_ERROR_NOSUCHTABLE,            2291 => MDB_ERROR_CONSTRAINT,            2449 => MDB_ERROR_CONSTRAINT,        );    }    // }}}    // {{{ errorNative()    /**     * Get the native error code of the last error (if any) that     * occured on the current connection.     *      * @access public      * @return int native oci8 error code     */    function errorNative($statement = NULL)    {        if (is_resource($statement)) {            $error = @OCIError($statement);        } else {            $error = @OCIError($this->connection);        }        if (is_array($error)) {            return($error['code']);        }        return(FALSE);    }    // }}}    // {{{ oci8RaiseError()    /**     * This method is used to communicate an error and invoke error     * callbacks etc.  Basically a wrapper for MDB::raiseError     * that checks for native error msgs.     *      * @param integer $errno error code     * @param string  $message userinfo message     * @return object a PEAR error object     * @access public      * @see PEAR_Error     */    function oci8RaiseError($errno = NULL, $message = NULL)    {        if ($errno === NULL) {            if ($this->connection) {                $error = @OCIError($this->connection);            } else {                $error = @OCIError();            }            return($this->raiseError($this->errorCode($error['code']),                NULL, NULL, $message, $error['message']));        } elseif (is_resource($errno)) {            $error = @OCIError($errno);            return($this->raiseError($this->errorCode($error['code']),                NULL, NULL, $message, $error['message']));        }        return($this->raiseError($this->errorCode($errno), NULL, NULL, $message));    }    // }}}    // {{{ autoCommit()    /**     * Define whether database changes done on the database be automatically     * committed. This function may also implicitly start or end a transaction.     *      * @param boolean $auto_commit flag that indicates whether the database     *                                 changes should be committed right after     *                                 executing every query statement. If this     *                                 argument is 0 a transaction implicitly     *                                 started. Otherwise, if a transaction is     *                                 in progress it is ended by committing any     *                                 database changes that were pending.     * @access public      * @return mixed MDB_OK on success, a MDB error on failure     */    function autoCommit($auto_commit)    {        $this->debug('AutoCommit: '.($auto_commit ? 'On' : 'Off'));        if ($this->auto_commit == $auto_commit) {            return(MDB_OK);        }        if ($this->connection && $auto_commit && MDB::isError($commit = $this->commit())) {            return($commit);        }        $this->auto_commit = $auto_commit;        $this->in_transaction = !$auto_commit;        return(MDB_OK);    }    // }}}    // {{{ commit()    /**     * Commit the database changes done during a transaction that is in     * progress. This function may only be called when auto-committing is     * disabled, otherwise it will fail. Therefore, a new transaction is     * implicitly started after committing the pending changes.     *      * @access public      * @return mixed MDB_OK on success, a MDB error on failure     */    function commit()    {        $this->debug('Commit Transaction');        if (!isset($this->supported['Transactions'])) {            return($this->raiseError(MDB_ERROR_UNSUPPORTED, NULL, NULL,                'Commit transactions: transactions are not in use'));        }        if ($this->auto_commit) {            return($this->raiseError(MDB_ERROR, NULL, NULL,            'Commit transactions: transaction changes are being auto commited'));        }        if ($this->uncommitedqueries) {            if (!@OCICommit($this->connection)) {                return($this->oci8RaiseError(NULL,                    'Commit transactions: Could not commit pending transaction: '."$message. Error: ".$error['code'].' ('.$error['message'].')'));            }            $this->uncommitedqueries = 0;        }        return(MDB_OK);    }    // }}}    // {{{ rollback()    /**     * Cancel any database changes done during a transaction that is in     * progress. This function may only be called when auto-committing is     * disabled, otherwise it will fail. Therefore, a new transaction is     * implicitly started after canceling the pending changes.     *      * @access public      * @return mixed MDB_OK on success, a MDB error on failure     */    function rollback()    {        $this->debug('Rollback Transaction');        if ($this->auto_commit) {            return($this->raiseError(MDB_ERROR, NULL, NULL,                'Rollback transactions: transactions can not be rolled back when changes are auto commited'));        }        if ($this->uncommitedqueries) {            if (!@OCIRollback($this->connection)) {                return($this->oci8RaiseError(NULL,                    'Rollback transaction: Could not rollback pending transaction'));            }            $this->uncommitedqueries = 0;        }        return(MDB_OK);    }    // }}}    // {{{ connect()    /**     * Connect to the database     *      * @return TRUE on success, MDB_Error on failure     */    function connect($user = NULL , $password = NULL, $persistent = NULL)    {        if($user === NULL) {            $user = $this->user;        }        if($password === NULL) {            $password = $this->password;        }        if($persistent === NULL) {            $persistent = $this->getOption('persistent');        }        if (isset($this->host)) {            $sid = $this->host;        } else {            $sid = getenv('ORACLE_SID');        }        if(!strcmp($sid, '')) {            return($this->raiseError(MDB_ERROR, NULL, NULL,                'Connect: it was not specified a valid Oracle Service IDentifier (SID)'));        }        if($this->connection != 0) {            if (!strcmp($this->connected_user, $user)                && !strcmp($this->connected_password, $password)                && $this->opened_persistent == $persistent)            {                return(MDB_OK);            }            $this->_close();        }        if(!PEAR::loadExtension($this->phptype)) {            return(PEAR::raiseError(NULL, MDB_ERROR_NOT_FOUND,                NULL, NULL, 'extension '.$this->phptype.' is not compiled into PHP',                'MDB_Error', TRUE));        }        if (isset($this->options['HOME'])) {            putenv('ORACLE_HOME='.$this->options['HOME']);

⌨️ 快捷键说明

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