fbsql.php
来自「视频监控网络部分的协议ddns,的模块的实现代码,请大家大胆指正.」· PHP 代码 · 共 1,378 行 · 第 1/4 页
PHP
1,378 行
<?php// +----------------------------------------------------------------------+// | 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: Lukas Smith <smith@dybnet.de> |// +----------------------------------------------------------------------+//// $Id: fbsql.php,v 1.16.4.16 2004/04/08 17:19:00 lsmith Exp $//require_once('MDB/Common.php');/** * MDB FrontBase driver * * Notes: * - This driver is fairly untested at this time and shoukd be considered * alpha quality for this reason * * @package MDB * @category Database * @author Lukas Smith <smith@dybnet.de> * @author Frank M. Kromann <frank@kromann.info> */class MDB_fbsql 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 $decimal_factor = 1.0; var $max_text_length = 32768; var $highest_fetched_row = array(); var $columns = array(); // }}} // {{{ constructor /** * Constructor */ function MDB_fbsql() { $this->MDB_Common(); $this->phptype = 'fbsql'; $this->dbsyntax = 'fbsql'; $this->supported['Sequences'] = 1; $this->supported['Indexes'] = 1; $this->supported['AffectedRows'] = 1; $this->supported['Summaryfunctions'] = 1; $this->supported['OrderByText'] = 1; $this->supported['CurrId'] = 0; $this->supported['SelectRowRanges'] = 1; $this->supported['LOBs'] = 1; $this->supported['Replace'] = 1; $this->supported['SubSelects'] = 1; $this->decimal_factor = pow(10.0, $this->decimal_places); $this->errorcode_map = array( 1004 => MDB_ERROR_CANNOT_CREATE, 1005 => MDB_ERROR_CANNOT_CREATE, 1006 => MDB_ERROR_CANNOT_CREATE, 1007 => MDB_ERROR_ALREADY_EXISTS, 1008 => MDB_ERROR_CANNOT_DROP, 1046 => MDB_ERROR_NODBSELECTED, 1050 => MDB_ERROR_ALREADY_EXISTS, 1051 => MDB_ERROR_NOSUCHTABLE, 1054 => MDB_ERROR_NOSUCHFIELD, 1062 => MDB_ERROR_ALREADY_EXISTS, 1064 => MDB_ERROR_SYNTAX, 1100 => MDB_ERROR_NOT_LOCKED, 1136 => MDB_ERROR_VALUE_COUNT_ON_ROW, 1146 => MDB_ERROR_NOSUCHTABLE, ); } // }}} // {{{ 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() { return @fbsql_errno($this->connection); } // }}} // {{{ fbsqlRaiseError() /** * 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 fbsqlRaiseError($errno = NULL, $message = NULL) { if ($errno == NULL) { if ($this->connection) { $errno = @fbsql_errno($this->connection); } else { $errno = @fbsql_errno(); } } if ($this->connection) { $error = @fbsql_errno($this->connection); } else { $error = @fbsql_error(); } return($this->raiseError($this->errorCode($errno), NULL, NULL, $message, $error)); } // }}} // {{{ 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'); if (MDB::isError($result)) { return($result); } $result = $this->query('SET COMMIT TRUE'); } else { $result = $this->query('SET COMMIT FALSE'); } 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')); } return($this->query('COMMIT')); } // }}} // {{{ 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')); } return($this->query('ROLLBACK')); } // }}} // {{{ connect() /** * Connect to the database * * @return TRUE on success, MDB_Error on failure **/ function connect() { $port = (isset($this->port) ? $this->port : 0); 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); } @fbsql_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'] ? 'fbsql_pconnect' : 'fbsql_connect'); if(!function_exists($function)) { return($this->raiseError(MDB_ERROR_UNSUPPORTED)); } @ini_set('track_errors', TRUE); $this->connection = @$function( $port > 0 ? $port : $this->host, $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) { if (!@fbsql_query('SET AUTOCOMMIT FALSE;', $this->connection)) { @fbsql_close($this->connection); $this->connection = 0; $this->affected_rows = -1; return($this->raiseError()); } $this->in_transaction = TRUE; } $this->connected_host = $this->host; $this->connected_user = $this->user; $this->connected_password = $this->password; $this->connected_port = $port; $this->opened_persistent = $this->options['persistent']; return(MDB_OK); } // }}} // {{{ _close() /** * all the RDBMS specific things needed close a DB connection * * @return boolean * @access private **/ function _close() {
⌨️ 快捷键说明
复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?