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

📄 adodb.inc.php

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

	 *

	 * @return return true or false

	 */	

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

	{

		if (defined('ADODB_NEVER_PERSIST')) 

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

		

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

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

		if ($argPassword != "") $this->password = $argPassword;

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

			

		$this->_isPersistentConnection = true;	

		

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

			if ($this->_pconnect($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,'PCONNECT',$this->ErrorNo(),$err,$this->host,$this->database,$this);

		} else 

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



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

		return false;

	}



	// Format date column in sql string given an input format that understands Y M D

	function SQLDate($fmt, $col=false)

	{	

		if (!$col) $col = $this->sysDate;

		return $col; // child class implement

	}

	

	/**

	 * Should prepare the sql statement and return the stmt resource.

	 * For databases that do not support this, we return the $sql. To ensure

	 * compatibility with databases that do not support prepare:

	 *

	 *   $stmt = $db->Prepare("insert into table (id, name) values (?,?)");

	 *   $db->Execute($stmt,array(1,'Jill')) or die('insert failed');

	 *   $db->Execute($stmt,array(2,'Joe')) or die('insert failed');

	 *

	 * @param sql	SQL to send to database

	 *

	 * @return return FALSE, or the prepared statement, or the original sql if

	 * 			if the database does not support prepare.

	 *

	 */	

	function Prepare($sql)

	{

		return $sql;

	}



	/**

	 * Some databases, eg. mssql require a different function for preparing

	 * stored procedures. So we cannot use Prepare().

	 *

	 * Should prepare the stored procedure  and return the stmt resource.

	 * For databases that do not support this, we return the $sql. To ensure

	 * compatibility with databases that do not support prepare:

	 *

	 * @param sql	SQL to send to database

	 *

	 * @return return FALSE, or the prepared statement, or the original sql if

	 * 			if the database does not support prepare.

	 *

	 */	

	function PrepareSP($sql,$param=true)

	{

		return $this->Prepare($sql,$param);

	}

	

	/**

	* PEAR DB Compat

	*/

	function Quote($s)

	{

		return $this->qstr($s,false);

	}

	

	/**

	 Requested by "Karsten Dambekalns" <k.dambekalns@fishfarm.de>

	*/

	function QMagic($s)

	{

		return $this->qstr($s,get_magic_quotes_gpc());

	}



	function q(&$s)

	{

		$s = $this->qstr($s,false);

	}

	

	/**

	* PEAR DB Compat - do not use internally. 

	*/

	function ErrorNative()

	{

		return $this->ErrorNo();

	}



	

   /**

	* PEAR DB Compat - do not use internally. 

	*/

	function nextId($seq_name)

	{

		return $this->GenID($seq_name);

	}



	/**

	*	 Lock a row, will escalate and lock the table if row locking not supported

	*	will normally free the lock at the end of the transaction

	*

	*  @param $table	name of table to lock

	*  @param $where	where clause to use, eg: "WHERE row=12". If left empty, will escalate to table lock

	*/

	function RowLock($table,$where)

	{

		return false;

	}

	

	function CommitLock($table)

	{

		return $this->CommitTrans();

	}

	

	function RollbackLock($table)

	{

		return $this->RollbackTrans();

	}

	

	/**

	* PEAR DB Compat - do not use internally. 

	*

	* The fetch modes for NUMERIC and ASSOC for PEAR DB and ADODB are identical

	* 	for easy porting :-)

	*

	* @param mode	The fetchmode ADODB_FETCH_ASSOC or ADODB_FETCH_NUM

	* @returns		The previous fetch mode

	*/

	function SetFetchMode($mode)

	{	

		$old = $this->fetchMode;

		$this->fetchMode = $mode;

		

		if ($old === false) {

		global $ADODB_FETCH_MODE;

			return $ADODB_FETCH_MODE;

		}

		return $old;

	}

	



	/**

	* PEAR DB Compat - do not use internally. 

	*/

	function &Query($sql, $inputarr=false)

	{

		$rs = &$this->Execute($sql, $inputarr);

		if (!$rs && defined('ADODB_PEAR')) return ADODB_PEAR_Error();

		return $rs;

	}



	

	/**

	* PEAR DB Compat - do not use internally

	*/

	function &LimitQuery($sql, $offset, $count, $params=false)

	{

		$rs = &$this->SelectLimit($sql, $count, $offset, $params); 

		if (!$rs && defined('ADODB_PEAR')) return ADODB_PEAR_Error();

		return $rs;

	}



	

	/**

	* PEAR DB Compat - do not use internally

	*/

	function Disconnect()

	{

		return $this->Close();

	}

	

	/*

		 Returns placeholder for parameter, eg.

		 $DB->Param('a')

		 

		 will return ':a' for Oracle, and '?' for most other databases...

		 

		 For databases that require positioned params, eg $1, $2, $3 for postgresql,

		 	pass in Param(false) before setting the first parameter.

	*/

	function Param($name)

	{

		return '?';

	}

	

	/*

		InParameter and OutParameter are self-documenting versions of Parameter().

	*/

	function InParameter(&$stmt,&$var,$name,$maxLen=4000,$type=false)

	{

		return $this->Parameter($stmt,$var,$name,false,$maxLen,$type);

	}

	

	/*

	*/

	function OutParameter(&$stmt,&$var,$name,$maxLen=4000,$type=false)

	{

		return $this->Parameter($stmt,$var,$name,true,$maxLen,$type);

	

	}

	

	/* 

	Usage in oracle

		$stmt = $db->Prepare('select * from table where id =:myid and group=:group');

		$db->Parameter($stmt,$id,'myid');

		$db->Parameter($stmt,$group,'group',64);

		$db->Execute();

		

		@param $stmt Statement returned by Prepare() or PrepareSP().

		@param $var PHP variable to bind to

		@param $name Name of stored procedure variable name to bind to.

		@param [$isOutput] Indicates direction of parameter 0/false=IN  1=OUT  2= IN/OUT. This is ignored in oci8.

		@param [$maxLen] Holds an maximum length of the variable.

		@param [$type] The data type of $var. Legal values depend on driver.



	*/

	function Parameter(&$stmt,&$var,$name,$isOutput=false,$maxLen=4000,$type=false)

	{

		return false;

	}

	

	/**

		Improved method of initiating a transaction. Used together with CompleteTrans().

		Advantages include:

		

		a. StartTrans/CompleteTrans is nestable, unlike BeginTrans/CommitTrans/RollbackTrans.

		   Only the outermost block is treated as a transaction.<br>

		b. CompleteTrans auto-detects SQL errors, and will rollback on errors, commit otherwise.<br>

		c. All BeginTrans/CommitTrans/RollbackTrans inside a StartTrans/CompleteTrans block

		   are disabled, making it backward compatible.

	*/

	function StartTrans($errfn = 'ADODB_TransMonitor')

	{

		if ($this->transOff > 0) {

			$this->transOff += 1;

			return;

		}

		

		$this->_oldRaiseFn = $this->raiseErrorFn;

		$this->raiseErrorFn = $errfn;

		$this->_transOK = true;

		

		if ($this->debug && $this->transCnt > 0) ADOConnection::outp("Bad Transaction: StartTrans called within BeginTrans");

		$this->BeginTrans();

		$this->transOff = 1;

	}

	

	/**

		Used together with StartTrans() to end a transaction. Monitors connection

		for sql errors, and will commit or rollback as appropriate.

		

		@autoComplete if true, monitor sql errors and commit and rollback as appropriate, 

		and if set to false force rollback even if no SQL error detected.

		@returns true on commit, false on rollback.

	*/

	function CompleteTrans($autoComplete = true)

	{

		if ($this->transOff > 1) {

			$this->transOff -= 1;

			return true;

		}

		$this->raiseErrorFn = $this->_oldRaiseFn;

		

		$this->transOff = 0;

		if ($this->_transOK && $autoComplete) {

			if (!$this->CommitTrans()) {

				$this->_transOK = false;

				if ($this->debug) ADOConnection::outp("Smart Commit failed");

			} else

				if ($this->debug) ADOConnection::outp("Smart Commit occurred");

		} else {

			$this->RollbackTrans();

			if ($this->debug) ADOCOnnection::outp("Smart Rollback occurred");

		}

		

		return $this->_transOK;

	}

	

	/*

		At the end of a StartTrans/CompleteTrans block, perform a rollback.

	*/

	function FailTrans()

	{

		if ($this->debug) 

			if ($this->transOff == 0) {

				ADOConnection::outp("FailTrans outside StartTrans/CompleteTrans");

			} else {

				ADOConnection::outp("FailTrans was called");

				adodb_backtrace();

			}

		$this->_transOK = false;

	}

	

	/**

		Check if transaction has failed, only for Smart Transactions.

	*/

	function HasFailedTrans()

	{

		if ($this->transOff > 0) return $this->_transOK == false;

		return false;

	}

	

	/**

	 * Execute SQL 

	 *

	 * @param sql		SQL statement to execute, or possibly an array holding prepared statement ($sql[0] will hold sql text)

	 * @param [inputarr]	holds the input data to bind to. Null elements will be set to null.

	 * @return 		RecordSet or false

	 */

	function &Execute($sql,$inputarr=false) 

	{

		if ($this->fnExecute) {

			$fn = $this->fnExecute;

			$ret =& $fn($this,$sql,$inputarr);

			if (isset($ret)) return $ret;

		}

		if ($inputarr && is_array($inputarr)) {

			$element0 = reset($inputarr);

			# is_object check is because oci8 descriptors can be passed in

			$array_2d = is_array($element0) && !is_object(reset($element0));

			

			if (!is_array($sql) && !$this->_bindInputArray) {

				$sqlarr = explode('?',$sql);

					

				if (!$array_2d) $inputarr = array($inputarr);

				foreach($inputarr as $arr) {

					$sql = ''; $i = 0;

					foreach($arr as $v) {

						$sql .= $sqlarr[$i];

						// from Ron Baldwin <ron.baldwin@sourceprose.com>

						// Only quote string types	

						if (gettype($v) == 'string')

							$sql .= $this->qstr($v);

						else if ($v === null)

							$sql .= 'NULL';

						else

							$sql .= $v;

						$i += 1;

					}

					$sql .= $sqlarr[$i];

					

					if ($i+1 != sizeof($sqlarr))	

						ADOConnection::outp( "Input Array does not match ?: ".htmlspecialchars($sql));

		

					$ret =& $this->_Execute($sql,false);

					if (!$ret) return $ret;

				}	

			} else {

				if ($array_2d) {

					$stmt = $this->Prepare($sql);

					foreach($inputarr as $arr) {

						$ret =& $this->_Execute($stmt,$arr);

						if (!$ret) return $ret;

					}

				} else

					$ret =& $this->_Execute($sql,$inputarr);

			}

		} else {

			$ret =& $this->_Execute($sql,false);

		}



		return $ret;

	}

	

	function& _Execute($sql,$inputarr=false)

	{



		if ($this->debug) {

		global $HTTP_SERVER_VARS;

		

			$ss = '';

			if ($inputarr) {

				foreach($inputarr as $kk=>$vv) {

					if (is_string($vv) && strlen($vv)>64) $vv = substr($vv,0,64).'...';

					$ss .= "($kk=>'$vv') ";

				}

				$ss = "[ $ss ]";

			}

			$sqlTxt = str_replace(',',', ',is_array($sql) ?$sql[0] : $sql);

			

			// check if running from browser or command-line

			$inBrowser = isset($HTTP_SERVER_VARS['HTTP_USER_AGENT']);

			

			if ($inBrowser) {

				if ($this->debug === -1)

					ADOConnection::outp( "<br>\n($this->databaseType): ".htmlspecialchars($sqlTxt)." &nbsp; <code>$ss</code>\n<br>\n",false);

				else 

					ADOConnection::outp( "<hr>\n($this->databaseType): ".htmlspecialchars($sqlTxt)." &nbsp; <code>$ss</code>\n<hr>\n",false);

			} else {

				ADOConnection::outp("-----\n($this->databaseType): ".($sqlTxt)." \n-----\n",false);

			}

			$this->_queryID = $this->_query($sql,$inputarr);

			/* 

				Alexios Fakios notes that ErrorMsg() must be called before ErrorNo() for mssql

				because ErrorNo() calls Execute('SELECT @ERROR'), causing recursion

			*/

			if ($this->databaseType == 'mssql') { 

			// ErrorNo is a slow function call in mssql, and not reliable in PHP 4.0.6

				if($emsg = $this->ErrorMsg()) {

					if ($err = $this->ErrorNo()) ADOConnection::outp($err.': '.$emsg);

				}

			} else if (!$this->_queryID) {

				ADOConnection::outp($this->ErrorNo() .': '. $this->ErrorMsg());

			}	

⌨️ 快捷键说明

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