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

📄 adodb.inc.php

📁 缺陷管理系统。Apache+PHP+MySQL 支持E-amil功能。是企业级开发中不可或缺的编程管理利器
💻 PHP
📖 第 1 页 / 共 5 页
字号:
<?php 

/*

 * Set tabs to 4 for best viewing.

 * 

 * Latest version is available at http://php.weblogs.com/adodb

 * 

 * This is the main include file for ADOdb.

 * Database specific drivers are stored in the adodb/drivers/adodb-*.inc.php

 *

 * The ADOdb files are formatted so that doxygen can be used to generate documentation.

 * Doxygen is a documentation generation tool and can be downloaded from http://doxygen.org/

 */



/**

	\mainpage 	

	

	 @version V4.22 15 Apr 2004 (c) 2000-2004 John Lim (jlim\@natsoft.com.my). All rights reserved.



	Released under both BSD license and Lesser GPL library license. You can choose which license

	you prefer.

	

	PHP's database access functions are not standardised. This creates a need for a database 

	class library to hide the differences between the different database API's (encapsulate 

	the differences) so we can easily switch databases.



	We currently support MySQL, Oracle, Microsoft SQL Server, Sybase, Sybase SQL Anywhere, DB2,

	Informix, PostgreSQL, FrontBase, Interbase (Firebird and Borland variants), Foxpro, Access,

	ADO, SAP DB, SQLite and ODBC. We have had successful reports of connecting to Progress and

	other databases via ODBC. 

	 

	Latest Download at http://php.weblogs.com/adodb<br>

	Manual is at http://php.weblogs.com/adodb_manual

	  

 */

 

 if (!defined('_ADODB_LAYER')) {

 	define('_ADODB_LAYER',1);

	

	//==============================================================================================	

	// CONSTANT DEFINITIONS

	//==============================================================================================	





	/** 

	 * Set ADODB_DIR to the directory where this file resides...

	 * This constant was formerly called $ADODB_RootPath

	 */

	if (!defined('ADODB_DIR')) define('ADODB_DIR',dirname(__FILE__));

	

	//==============================================================================================	

	// GLOBAL VARIABLES

	//==============================================================================================	



	GLOBAL 

		$ADODB_vers, 		// database version

		$ADODB_COUNTRECS,	// count number of records returned - slows down query

		$ADODB_CACHE_DIR,	// directory to cache recordsets

		$ADODB_EXTENSION,   // ADODB extension installed

		$ADODB_COMPAT_PATCH, // If $ADODB_COUNTRECS and this is true, $rs->fields is available on EOF

	 	$ADODB_FETCH_MODE;	// DEFAULT, NUM, ASSOC or BOTH. Default follows native driver default...

	

	//==============================================================================================	

	// GLOBAL SETUP

	//==============================================================================================	

	

	$ADODB_EXTENSION = defined('ADODB_EXTENSION');

	if (!$ADODB_EXTENSION || ADODB_EXTENSION < 4.0) {

		

		define('ADODB_BAD_RS','<p>Bad $rs in %s. Connection or SQL invalid. Try using $connection->debug=true;</p>');

	

	// allow [ ] @ ` " and . in table names

		define('ADODB_TABLE_REGEX','([]0-9a-z_\"\`\.\@\[-]*)');

	

	// prefetching used by oracle

		if (!defined('ADODB_PREFETCH_ROWS')) define('ADODB_PREFETCH_ROWS',10);

	

	

	/*

	Controls ADODB_FETCH_ASSOC field-name case. Default is 2, use native case-names.

	This currently works only with mssql, odbc, oci8po and ibase derived drivers.

	

 		0 = assoc lowercase field names. $rs->fields['orderid']

		1 = assoc uppercase field names. $rs->fields['ORDERID']

		2 = use native-case field names. $rs->fields['OrderID']

	*/

	

		define('ADODB_FETCH_DEFAULT',0);

		define('ADODB_FETCH_NUM',1);

		define('ADODB_FETCH_ASSOC',2);

		define('ADODB_FETCH_BOTH',3);

		

		if (!defined('TIMESTAMP_FIRST_YEAR')) define('TIMESTAMP_FIRST_YEAR',100);

	

		if (strnatcmp(PHP_VERSION,'4.3.0')>=0) {

			define('ADODB_PHPVER',0x4300);

		} else if (strnatcmp(PHP_VERSION,'4.2.0')>=0) {

			define('ADODB_PHPVER',0x4200);

		} else if (strnatcmp(PHP_VERSION,'4.0.5')>=0) {

			define('ADODB_PHPVER',0x4050);

		} else {

			define('ADODB_PHPVER',0x4000);

		}

	}

	

	//if (!defined('ADODB_ASSOC_CASE')) define('ADODB_ASSOC_CASE',2);

	

	

	/**

	 	Accepts $src and $dest arrays, replacing string $data

	*/

	function ADODB_str_replace($src, $dest, $data)

	{

		if (ADODB_PHPVER >= 0x4050) return str_replace($src,$dest,$data);

		

		$s = reset($src);

		$d = reset($dest);

		while ($s !== false) {

			$data = str_replace($s,$d,$data);

			$s = next($src);

			$d = next($dest);

		}

		return $data;

	}

	

	function ADODB_Setup()

	{

	GLOBAL 

		$ADODB_vers, 		// database version

		$ADODB_COUNTRECS,	// count number of records returned - slows down query

		$ADODB_CACHE_DIR,	// directory to cache recordsets

	 	$ADODB_FETCH_MODE;

		

		$ADODB_FETCH_MODE = ADODB_FETCH_DEFAULT;

		

		if (!isset($ADODB_CACHE_DIR)) {

			$ADODB_CACHE_DIR = '/tmp'; //(isset($_ENV['TMP'])) ? $_ENV['TMP'] : '/tmp';

		} else {

			// do not accept url based paths, eg. http:/ or ftp:/

			if (strpos($ADODB_CACHE_DIR,'://') !== false) 

				die("Illegal path http:// or ftp://");

		}

		

			

		// Initialize random number generator for randomizing cache flushes

		srand(((double)microtime())*1000000);

		

		/**

		 * ADODB version as a string.

		 */

		$ADODB_vers = 'V4.22 15 Apr 2004 (c) 2000-2004 John Lim (jlim#natsoft.com.my). All rights reserved. Released BSD & LGPL.';

	

		/**

		 * Determines whether recordset->RecordCount() is used. 

		 * Set to false for highest performance -- RecordCount() will always return -1 then

		 * for databases that provide "virtual" recordcounts...

		 */

		if (!isset($ADODB_COUNTRECS)) $ADODB_COUNTRECS = true; 

	}

	

	

	//==============================================================================================	

	// CHANGE NOTHING BELOW UNLESS YOU ARE DESIGNING ADODB

	//==============================================================================================	

	

	ADODB_Setup();



	//==============================================================================================	

	// CLASS ADOFieldObject

	//==============================================================================================	

	/**

	 * Helper class for FetchFields -- holds info on a column

	 */

	class ADOFieldObject { 

		var $name = '';

		var $max_length=0;

		var $type="";



		// additional fields by dannym... (danny_milo@yahoo.com)

		var $not_null = false; 

		// actually, this has already been built-in in the postgres, fbsql AND mysql module? ^-^

		// so we can as well make not_null standard (leaving it at "false" does not harm anyways)



		var $has_default = false; // this one I have done only in mysql and postgres for now ... 

			// others to come (dannym)

		var $default_value; // default, if any, and supported. Check has_default first.

	}

	



	

	function ADODB_TransMonitor($dbms, $fn, $errno, $errmsg, $p1, $p2, &$thisConnection)

	{

		//print "Errorno ($fn errno=$errno m=$errmsg) ";

		$thisConnection->_transOK = false;

		if ($thisConnection->_oldRaiseFn) {

			$fn = $thisConnection->_oldRaiseFn;

			$fn($dbms, $fn, $errno, $errmsg, $p1, $p2,$thisConnection);

		}

	}

	

	//==============================================================================================	

	// CLASS ADOConnection

	//==============================================================================================	

	

	/**

	 * Connection object. For connecting to databases, and executing queries.

	 */ 

	class ADOConnection {

	//

	// PUBLIC VARS 

	//

	var $dataProvider = 'native';

	var $databaseType = '';		/// RDBMS currently in use, eg. odbc, mysql, mssql					

	var $database = '';			/// Name of database to be used.	

	var $host = ''; 			/// The hostname of the database server	

	var $user = ''; 			/// The username which is used to connect to the database server. 

	var $password = ''; 		/// Password for the username. For security, we no longer store it.

	var $debug = false; 		/// if set to true will output sql statements

	var $maxblobsize = 256000; 	/// maximum size of blobs or large text fields -- some databases die otherwise like foxpro

	var $concat_operator = '+'; /// default concat operator -- change to || for Oracle/Interbase	

	var $substr = 'substr';		/// substring operator

	var $length = 'length';		/// string length operator

	var $random = 'rand()';		/// random function

	var $upperCase = false;		/// uppercase function

	var $fmtDate = "'Y-m-d'";	/// used by DBDate() as the default date format used by the database

	var $fmtTimeStamp = "'Y-m-d, h:i:s A'"; /// used by DBTimeStamp as the default timestamp fmt.

	var $true = '1'; 			/// string that represents TRUE for a database

	var $false = '0'; 			/// string that represents FALSE for a database

	var $replaceQuote = "\\'"; 	/// string to use to replace quotes

	var $nameQuote = '"';		/// string to use to quote identifiers and names

	var $charSet=false; 		/// character set to use - only for interbase

	var $metaDatabasesSQL = '';

	var $metaTablesSQL = '';

	var $uniqueOrderBy = false; /// All order by columns have to be unique

	var $emptyDate = '&nbsp;';

	var $emptyTimeStamp = '&nbsp;';

	var $lastInsID = false;

	//--

	var $hasInsertID = false; 		/// supports autoincrement ID?

	var $hasAffectedRows = false; 	/// supports affected rows for update/delete?

	var $hasTop = false;			/// support mssql/access SELECT TOP 10 * FROM TABLE

	var $hasLimit = false;			/// support pgsql/mysql SELECT * FROM TABLE LIMIT 10

	var $readOnly = false; 			/// this is a readonly database - used by phpLens

	var $hasMoveFirst = false;  /// has ability to run MoveFirst(), scrolling backwards

	var $hasGenID = false; 		/// can generate sequences using GenID();

	var $hasTransactions = true; /// has transactions

	//--

	var $genID = 0; 			/// sequence id used by GenID();

	var $raiseErrorFn = false; 	/// error function to call

	var $isoDates = false; /// accepts dates in ISO format

	var $cacheSecs = 3600; /// cache for 1 hour

	var $sysDate = false; /// name of function that returns the current date

	var $sysTimeStamp = false; /// name of function that returns the current timestamp

	var $arrayClass = 'ADORecordSet_array'; /// name of class used to generate array recordsets, which are pre-downloaded recordsets

	

	var $noNullStrings = false; /// oracle specific stuff - if true ensures that '' is converted to ' '

	var $numCacheHits = 0; 

	var $numCacheMisses = 0;

	var $pageExecuteCountRows = true;

	var $uniqueSort = false; /// indicates that all fields in order by must be unique

	var $leftOuter = false; /// operator to use for left outer join in WHERE clause

	var $rightOuter = false; /// operator to use for right outer join in WHERE clause

	var $ansiOuter = false; /// whether ansi outer join syntax supported

	var $autoRollback = false; // autoRollback on PConnect().

	var $poorAffectedRows = false; // affectedRows not working or unreliable

	

	var $fnExecute = false;

	var $fnCacheExecute = false;

	var $blobEncodeType = false; // false=not required, 'I'=encode to integer, 'C'=encode to char

	var $rsPrefix = "ADORecordSet_";

	

	var $autoCommit = true; 	/// do not modify this yourself - actually private

	var $transOff = 0; 			/// temporarily disable transactions

	var $transCnt = 0; 			/// count of nested transactions

	

	var $fetchMode=false;

	 //

	 // PRIVATE VARS

	 //

	var $_oldRaiseFn =  false;

	var $_transOK = null;

	var $_connectionID	= false;	/// The returned link identifier whenever a successful database connection is made.	

	var $_errorMsg = false;		/// A variable which was used to keep the returned last error message.  The value will

								/// then returned by the errorMsg() function	

	var $_errorCode = false;	/// Last error code, not guaranteed to be used - only by oci8					

	var $_queryID = false;		/// This variable keeps the last created result link identifier

	

	var $_isPersistentConnection = false;	/// A boolean variable to state whether its a persistent connection or normal connection.	*/

	var $_bindInputArray = false; /// set to true if ADOConnection.Execute() permits binding of array parameters.

	var $_evalAll = false;

	var $_affected = false;

	var $_logsql = false;

	



	

	/**

	 * Constructor

	 */

	function ADOConnection()			

	{

		die('Virtual Class -- cannot instantiate');

	}

	

	/**

		Get server version info...

		

		@returns An array with 2 elements: $arr['string'] is the description string, 

			and $arr[version] is the version (also a string).

	*/

	function ServerInfo()

	{

		return array('description' => '', 'version' => '');

	}

	

	function _findvers($str)

	{

		if (preg_match('/([0-9]+\.([0-9\.])+)/',$str, $arr)) return $arr[1];

		else return '';

	}

	

	/**

	* All error messages go through this bottleneck function.

	* You can define your own handler by defining the function name in ADODB_OUTP.

	*/

	function outp($msg,$newline=true)

	{

	global $HTTP_SERVER_VARS,$ADODB_FLUSH,$ADODB_OUTP;

	

		if (defined('ADODB_OUTP')) {

			$fn = ADODB_OUTP;

			$fn($msg,$newline);

			return;

		} else if (isset($ADODB_OUTP)) {

			$fn = $ADODB_OUTP;

			$fn($msg,$newline);

			return;

		}

		

		if ($newline) $msg .= "<br>\n";

		

		if (isset($HTTP_SERVER_VARS['HTTP_USER_AGENT'])) echo $msg;

		else echo strip_tags($msg);

		if (!empty($ADODB_FLUSH) && ob_get_length() !== false) flush(); //  dp not flush if output buffering enabled - useless - thx to Jesse Mullan 

		

	}

	

	function Time()

	{

		$rs =& $this->Execute("select $this->sysTimeStamp");

		if ($rs && !$rs->EOF) return $this->UnixTimeStamp(reset($rs->fields));

		

		return false;

	}

	

	/**

	 * Connect to database

	 *

	 * @param [argHostname]		Host to connect to

	 * @param [argUsername]		Userid to login

	 * @param [argPassword]		Associated password

	 * @param [argDatabaseName]	database

	 * @param [forceNew]		force new connection

	 *

	 * @return true or false

	 */	  

	function Connect($argHostname = "", $argUsername = "", $argPassword = "", $argDatabaseName = "", $forceNew = false) 

	{

		if ($argHostname != "") $this->host = $argHostname;

		if ($argUsername != "") $this->user = $argUsername;

		if ($argPassword != "") $this->password = $argPassword; // not stored for security reasons

		if ($argDatabaseName != "") $this->database = $argDatabaseName;		

		

		$this->_isPersistentConnection = false;	

		if ($fn = $this->raiseErrorFn) {

			if ($forceNew) {

				if ($this->_nconnect($this->host, $this->user, $this->password, $this->database)) return true;

			} else {

				 if ($this->_connect($this->host, $this->user, $this->password, $this->database)) return true;

			}

			$err = $this->ErrorMsg();

			if (empty($err)) $err = "Connection error to server '$argHostname' with user '$argUsername'";

			$fn($this->databaseType,'CONNECT',$this->ErrorNo(),$err,$this->host,$this->database,$this);

		} else {

			if ($forceNew) {

				if ($this->_nconnect($this->host, $this->user, $this->password, $this->database)) return true;

			} else {

				if ($this->_connect($this->host, $this->user, $this->password, $this->database)) return true;

			}

		}

		if ($this->debug) ADOConnection::outp( $this->host.': '.$this->ErrorMsg());

		return false;

	}	

	

	 function _nconnect($argHostname, $argUsername, $argPassword, $argDatabaseName)

	 {

	 	return $this->_connect($argHostname, $argUsername, $argPassword, $argDatabaseName);

	 }

	

	

	/**

	 * Always force a new connection to database - currently only works with oracle

	 *

	 * @param [argHostname]		Host to connect to

	 * @param [argUsername]		Userid to login

	 * @param [argPassword]		Associated password

	 * @param [argDatabaseName]	database

	 *

	 * @return true or false

	 */	  

	function NConnect($argHostname = "", $argUsername = "", $argPassword = "", $argDatabaseName = "") 

	{

		return $this->Connect($argHostname, $argUsername, $argPassword, $argDatabaseName, true);

	}

	

	/**

	 * Establish persistent connect to database

	 *

	 * @param [argHostname]		Host to connect to

	 * @param [argUsername]		Userid to login

	 * @param [argPassword]		Associated password

⌨️ 快捷键说明

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