mssql.php

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

PHP
1,425
字号
<?php// vim: set et ts=4 sw=4 fdm=marker:// +----------------------------------------------------------------------+// | PHP Version 4                                                        |// +----------------------------------------------------------------------+// | Copyright (c) 1998-2004 Manuel Lemos, Tomas V.V.Cox,                 |// | Stig. S. Bakken, Lukas Smith, Frank M. Kromann                       |// | 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: Frank M. Kromann <frank@kromann.info>                        |// +----------------------------------------------------------------------+//// $Id: mssql.php,v 1.6.4.30 2004/04/10 07:57:16 lsmith Exp $//require_once('MDB/Common.php');/** * MDB MSSQL Server driver * * Notes: * - Until at least version 6.5, the only kind of table changes that the *   ALTER TABLE SQL statement of Microsoft SQL server supports is new field     and constraint additions. * * - The driver alterTable method does not implement table or column renaming, *   column definitions changes or column dropping. In the future versions of *   this driver those capabilities may be emulated using other SQL statements *   to recreate the tables with a new definition. * *   MDB_Manager_mssql::getTableFieldDefinition() is still alpha quality * * @package MDB * @category Database * @author  Frank M. Kromann <frank@kromann.info> */class MDB_mssql extends MDB_Common{    // {{{ properties    var $connection = 0;    var $connected_host;    var $connected_user;    var $connected_password;    var $connected_port;    var $opened_persistent = '';    var $escape_quotes = "'";    var $highest_fetched_row = array();    var $columns = array();    // }}}    // {{{ constructor    /**    * Constructor    */    function MDB_mssql()    {        $this->MDB_Common();        $this->phptype = 'mssql';        $this->dbsyntax = 'mssql';        $this->supported['Sequences'] = 1;        $this->supported['Indexes'] = 1;        $this->supported['AffectedRows'] = 1;        $this->supported['Transactions'] = 1;        $this->supported['Summaryfunctions'] = 1;        $this->supported['OrderByText'] = 0;        $this->supported['CurrId'] = 0;        $this->supported['SelectRowRanges'] = 1;        $this->supported['LOBs'] = 1;        $this->supported['Replace'] = 1;        $this->supported['SubSelects'] = 1;        $this->errorcode_map = array(            207   => MDB_ERROR_NOSUCHFIELD,            208   => MDB_ERROR_NOSUCHTABLE,            245   => MDB_ERROR_INVALID_NUMBER,            515   => MDB_ERROR_CONSTRAINT_NOT_NULL,            547   => MDB_ERROR_CONSTRAINT,            1205  => MDB_ERROR_DEADLOCK,            2627  => MDB_ERROR_CONSTRAINT,            2714  => MDB_ERROR_ALREADY_EXISTS,            3701  => MDB_ERROR_NOSUCHTABLE,            8134  => MDB_ERROR_DIVZERO,        );    }    // }}}    // {{{ errorNative()    /**     * Get the native error code of the last error (if any) that     * occured on the current connection.     *     * @access public     *     * @return int native FrontBase error code     */    function errorNative()    {       $res = @mssql_query('select @@ERROR as ErrorCode', $this->connection);       if ($res) {           $row = @mssql_fetch_row($res);           if (is_array($row) && $row[0] > 0) {               return $row[0];           }       }       return NULL;    }    // }}}    // {{{ mssqlRaiseError()    /**     * 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 string  $message userinfo message     * @param integer $errno error code     * @return object a PEAR error object     * @access public     * @see PEAR_Error     */    function mssqlRaiseError($errno = NULL, $message = NULL)    {        if ($errno == NULL) {            $errno = $this->errorNative();        }        $error = @mssql_get_last_message();        return $this->raiseError($this->errorCode(), NULL, NULL,            $message, $error);    }    // }}}    // {{{ quoteIdentifier()    /**     * Quote a string so it can be safely used as a table / column name     *     * Quoting style depends on which database driver is being used.     *     * @param string $str  identifier name to be quoted     *     * @return string  quoted identifier string     *     * @since 1.6.0     * @access public     */    function quoteIdentifier($str)    {        return '[' . str_replace(']', ']]', $str) . ']';    }    // }}}    // {{{ 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 (!isset($this->supported['Transactions'])) {            return($this->raiseError(MDB_ERROR_UNSUPPORTED, NULL, NULL,                'Auto-commit transactions: transactions are not in use'));        }        if ($this->auto_commit == $auto_commit) {            return(MDB_OK);        }        if ($this->connection) {            if ($auto_commit) {                $result = $this->query('COMMIT TRANSACTION');            } else {                $result = $this->query('BEGIN TRANSACTION');            }            if (MDB::isError($result)) {                return($result);            }        }        $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'));        }        $result = $this->query('COMMIT TRANSACTION');        if (MDB::isError($result)) {            return($result);        }        return($this->query('BEGIN TRANSACTION'));    }    // }}}    // {{{ 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 (!isset($this->supported['Transactions'])) {            return($this->raiseError(MDB_ERROR_UNSUPPORTED, NULL, NULL,                'Rollback transactions: transactions are not in use'));        }        if ($this->auto_commit) {            return($this->raiseError(MDB_ERROR, NULL, NULL,                'Rollback transactions: transactions can not be rolled back when changes are auto commited'));        }        $result = $this->query('ROLLBACK TRANSACTION');        if (MDB::isError($result)) {            return($result);        }        return($this->query('BEGIN TRANSACTION'));    }    function _doQuery($query)    {        $this->current_row = $this->affected_rows = -1;        return(@mssql_query($query, $this->connection));    }    // }}}    // {{{ connect()    /**     * Connect to the database     *     * @return TRUE on success, MDB_Error on failure     **/    function connect()    {        $port = (isset($this->port) ? $this->port : '');        if($this->connection != 0) {            if (!strcmp($this->connected_host, $this->host)                && !strcmp($this->connected_user, $this->user)                && !strcmp($this->connected_password, $this->password)                && !strcmp($this->connected_port, $port)                && $this->opened_persistent == $this->options['persistent'])            {                return(MDB_OK);            }            @mssql_close($this->connection);            $this->connection = 0;            $this->affected_rows = -1;        }        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));        }        $function = ($this->options['persistent'] ? 'mssql_pconnect' : 'mssql_connect');        if (!function_exists($function)) {            return($this->raiseError(MDB_ERROR_UNSUPPORTED));        }        @ini_set('track_errors', TRUE);        $this->connection = @$function(            $this->host.(!strcmp($port,'') ? '' : ':'.$port),            $this->user, $this->password);        @ini_restore('track_errors');        if ($this->connection <= 0) {            return($this->raiseError(MDB_ERROR_CONNECT_FAILED, NULL, NULL,                $php_errormsg));        }        if(isset($this->supported['Transactions']) && !$this->auto_commit            && !$this->_doQuery("BEGIN TRANSACTION"))        {            @mssql_close($this->connection);            $this->connection = 0;            $this->affected_rows = -1;            return($this->raiseError("Connect: Could not begin the initial transaction"));        }        $this->connected_host = $this->host;

⌨️ 快捷键说明

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