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

📄 class.ux_t3lib_db.php

📁 Typo3, 开源里边最强大的
💻 PHP
📖 第 1 页 / 共 5 页
字号:
				else {					$sqlResult = mysql_query($this->lastQuery[0], $this->handlerInstance[$this->lastHandlerKey]['link']);					foreach($this->lastQuery[1] as $field => $content) {						mysql_query('UPDATE '.$this->quoteFromTables($table).' SET '.$this->quoteFromTables($field).'='.$this->fullQuoteStr($content,$table).' WHERE '.$this->quoteWhereClause($where), $this->handlerInstance[$this->lastHandlerKey]['link']);					}				}				break;			case 'adodb':					// auto generate ID for auto_increment fields if not present (static import needs this!)					// should we check the table name here (static_*)?				if(isset($this->cache_autoIncFields[$table])) {					if(isset($fields_values[$this->cache_autoIncFields[$table]])) {						$new_id = $fields_values[$this->cache_autoIncFields[$table]];						if($table !== 'tx_dbal_debuglog') {							$this->handlerInstance[$this->lastHandlerKey]->last_insert_id = $new_id;						}					} else {						$new_id = $this->handlerInstance[$this->lastHandlerKey]->GenID($table.'_'.$this->cache_autoIncFields[$table], $this->handlerInstance[$this->lastHandlerKey]->sequenceStart);						$fields_values[$this->cache_autoIncFields[$table]] = $new_id;						if($table !== 'tx_dbal_debuglog') {							$this->handlerInstance[$this->lastHandlerKey]->last_insert_id = $new_id;						}					}				}				$this->lastQuery = $this->INSERTquery($table,$fields_values,$no_quote_fields);				if(is_string($this->lastQuery)) {					$sqlResult = $this->handlerInstance[$this->lastHandlerKey]->_query($this->lastQuery,false);				} else {					$this->handlerInstance[$this->lastHandlerKey]->StartTrans();					if(strlen($this->lastQuery[0]))						$sqlResult = $this->handlerInstance[$this->lastHandlerKey]->_query($this->lastQuery[0],false);					foreach($this->lastQuery[1] as $field => $content) {						if(empty($content)) continue;						if(isset($this->cache_autoIncFields[$table]) && isset($new_id)) {							$this->handlerInstance[$this->lastHandlerKey]->UpdateBlob($this->quoteFromTables($table),$field,$content,$this->quoteWhereClause($this->cache_autoIncFields[$table].'='.$new_id));						} elseif(isset($this->cache_primaryKeys[$table])) {							$pks = explode(',', $this->cache_primaryKeys[$table]);							foreach ($pks as $pk) {								if(isset($fields_values[$pk]))								$where .= $pk.'='.$this->fullQuoteStr($fields_values[$pk], $table).' AND ';							}							$where = $this->quoteWhereClause($where.'1=1');							$this->handlerInstance[$this->lastHandlerKey]->UpdateBlob($this->quoteFromTables($table),$field,$content,$where);						} else {							$this->handlerInstance[$this->lastHandlerKey]->CompleteTrans(false);							die('Could not update BLOB >>>> no WHERE clause found!'); // should never ever happen						}					}					$this->handlerInstance[$this->lastHandlerKey]->CompleteTrans();				}				break;			case 'userdefined':				$sqlResult = $this->handlerInstance[$this->lastHandlerKey]->exec_INSERTquery($table,$fields_values,$no_quote_fields);				break;		}		if ($this->printErrors && $this->sql_error())	{			debug(array($this->lastQuery, $this->sql_error()));		}		if ($this->debug)	{			$this->debugHandler(				'exec_INSERTquery',				t3lib_div::milliseconds()-$pt,				array(					'handlerType' => $hType,					'args' => array($table,$fields_values),					'ORIG_tablename' => $ORIG_tableName				)			);		}			// Return output:		return $sqlResult;	}	/**	 * Updates a record from $table	 *	 * @param	string		Database tablename	 * @param	string		WHERE clause, eg. "uid=1". NOTICE: You must escape values in this argument with $this->fullQuoteStr() yourself!	 * @param	array		Field values as key=>value pairs. Values will be escaped internally. Typically you would fill an array like "$updateFields" with 'fieldname'=>'value' and pass it to this function as argument.	 * @param mixed    List/array of keys NOT to quote (eg. SQL functions)	 * @return	mixed		Result from handler, usually TRUE when success and FALSE on failure	 */	function exec_UPDATEquery($table,$where,$fields_values,$no_quote_fields='')	{		if ($this->debug)	$pt = t3lib_div::milliseconds();		// Do table/field mapping:		$ORIG_tableName = $table;		if ($tableArray = $this->map_needMapping($table))	{			// Field mapping of array:			$fields_values = $this->map_assocArray($fields_values,$tableArray);			// Where clause table and field mapping:			$whereParts = $this->SQLparser->parseWhereClause($where);			$this->map_sqlParts($whereParts,$tableArray[0]['table']);			$where = $this->SQLparser->compileWhereClause($whereParts);			// Table name:			if ($this->mapping[$table]['mapTableName'])	{				$table = $this->mapping[$table]['mapTableName'];			}		}		// Select API		$this->lastHandlerKey = $this->handler_getFromTableList($ORIG_tableName);		switch((string)$this->handlerCfg[$this->lastHandlerKey]['type'])	{			case 'native':				$this->lastQuery = $this->UPDATEquery($table,$where,$fields_values,$no_quote_fields);				if(is_string($this->lastQuery)) {					$sqlResult = mysql_query($this->lastQuery, $this->handlerInstance[$this->lastHandlerKey]['link']);				}				else {					$sqlResult = mysql_query($this->lastQuery[0], $this->handlerInstance[$this->lastHandlerKey]['link']);					foreach($this->lastQuery[1] as $field => $content) {						mysql_query('UPDATE '.$this->quoteFromTables($table).' SET '.$this->quoteFromTables($field).'='.$this->fullQuoteStr($content,$table).' WHERE '.$this->quoteWhereClause($where), $this->handlerInstance[$this->lastHandlerKey]['link']);					}				}			break;			case 'adodb':				$this->lastQuery = $this->UPDATEquery($table,$where,$fields_values,$no_quote_fields);				if(is_string($this->lastQuery)) {					$sqlResult = $this->handlerInstance[$this->lastHandlerKey]->_query($this->lastQuery,false);				} else {					$this->handlerInstance[$this->lastHandlerKey]->StartTrans();					if(strlen($this->lastQuery[0]))						$sqlResult = $this->handlerInstance[$this->lastHandlerKey]->_query($this->lastQuery[0],false);					foreach($this->lastQuery[1] as $field => $content) {						$this->handlerInstance[$this->lastHandlerKey]->UpdateBlob($this->quoteFromTables($table),$field,$content,$this->quoteWhereClause($where));					}					$this->handlerInstance[$this->lastHandlerKey]->CompleteTrans();				}				break;			case 'userdefined':				$sqlResult = $this->handlerInstance[$this->lastHandlerKey]->exec_UPDATEquery($table,$where,$fields_values,$no_quote_fields);				break;		}		if ($this->printErrors && $this->sql_error())	{			debug(array($this->lastQuery, $this->sql_error()));		}		if ($this->debug)	{			$this->debugHandler(				'exec_UPDATEquery',				t3lib_div::milliseconds()-$pt,				array(					'handlerType' => $hType,					'args' => array($table,$where, $fields_values),					'ORIG_from_table' => $ORIG_tableName				)			);		}			// Return result:		return $sqlResult;	}	/**	 * Deletes records from table	 *	 * @param	string		Database tablename	 * @param	string		WHERE clause, eg. "uid=1". NOTICE: You must escape values in this argument with $this->fullQuoteStr() yourself!	 * @return	mixed		Result from handler	 */	function exec_DELETEquery($table,$where)	{		if ($this->debug)	$pt = t3lib_div::milliseconds();			// Do table/field mapping:		$ORIG_tableName = $table;		if ($tableArray = $this->map_needMapping($table))	{				// Where clause:			$whereParts = $this->SQLparser->parseWhereClause($where);			$this->map_sqlParts($whereParts,$tableArray[0]['table']);			$where = $this->SQLparser->compileWhereClause($whereParts);				// Table name:			if ($this->mapping[$table]['mapTableName'])	{				$table = $this->mapping[$table]['mapTableName'];			}		}			// Select API		$this->lastHandlerKey = $this->handler_getFromTableList($ORIG_tableName);		switch((string)$this->handlerCfg[$this->lastHandlerKey]['type'])	{			case 'native':				$this->lastQuery = $this->DELETEquery($table,$where);				$sqlResult = mysql_query($this->lastQuery, $this->handlerInstance[$this->lastHandlerKey]['link']);				break;			case 'adodb':				$this->lastQuery = $this->DELETEquery($table,$where);				$sqlResult = $this->handlerInstance[$this->lastHandlerKey]->_query($this->lastQuery,false);				break;			case 'userdefined':				$sqlResult = $this->handlerInstance[$this->lastHandlerKey]->exec_DELETEquery($table,$where);				break;		}		if ($this->printErrors && $this->sql_error())	{			debug(array($this->lastQuery, $this->sql_error()));		}		if ($this->debug)	{			$this->debugHandler(				'exec_DELETEquery',				t3lib_div::milliseconds()-$pt,				array(					'handlerType' => $hType,					'args' => array($table,$where),					'ORIG_from_table' => $ORIG_tableName				)			);		}			// Return result:		return $sqlResult;	}	/**	 * Selects records from Data Source	 *	 * @param	string $select_fields List of fields to select from the table. This is what comes right after "SELECT ...". Required value.	 * @param	string $from_table Table(s) from which to select. This is what comes right after "FROM ...". Required value.	 * @param	string $where_clause Optional additional WHERE clauses put in the end of the query. NOTICE: You must escape values in this argument with $this->fullQquoteStr() yourself! DO NOT PUT IN GROUP BY, ORDER BY or LIMIT!	 * @param	string $groupBy Optional GROUP BY field(s), if none, supply blank string.	 * @param	string $orderBy Optional ORDER BY field(s), if none, supply blank string.	 * @param	string $limit Optional LIMIT value ([begin,]max), if none, supply blank string.	 * @return	mixed		Result from handler. Typically object from DBAL layers.	 */	function exec_SELECTquery($select_fields,$from_table,$where_clause,$groupBy='',$orderBy='',$limit='')	{		if ($this->debug)	$pt = t3lib_div::milliseconds();			// Map table / field names if needed:		$ORIG_tableName = $from_table;	// Saving table names in $ORIG_from_table since $from_table is transformed beneath:		if ($tableArray = $this->map_needMapping($ORIG_tableName))	{			$this->map_remapSELECTQueryParts($select_fields,$from_table,$where_clause,$groupBy,$orderBy);	// Variables passed by reference!		}			// Get handler key and select API:		$this->lastHandlerKey = $this->handler_getFromTableList($ORIG_tableName);		$hType = (string)$this->handlerCfg[$this->lastHandlerKey]['type'];		switch($hType)	{			case 'native':				$this->lastQuery = $this->SELECTquery($select_fields,$from_table,$where_clause,$groupBy,$orderBy,$limit);				$sqlResult = mysql_query($this->lastQuery, $this->handlerInstance[$this->lastHandlerKey]['link']);				$this->resourceIdToTableNameMap[(string)$sqlResult] = $ORIG_tableName;				break;			case 'adodb':				if ($limit!='')	{					$splitLimit = t3lib_div::intExplode(',',$limit);		// Splitting the limit values:					if ($splitLimit[1])	{	// If there are two parameters, do mapping differently than otherwise:						$numrows = $splitLimit[1];						$offset = $splitLimit[0];					} else {						$numrows = $splitLimit[0];						$offset = 0;					}					$sqlResult = $this->handlerInstance[$this->lastHandlerKey]->SelectLimit($this->SELECTquery($select_fields,$from_table,$where_clause,$groupBy,$orderBy), $numrows, $offset);					$this->lastQuery = $sqlResult->sql;				} else {					$this->lastQuery = $this->SELECTquery($select_fields,$from_table,$where_clause,$groupBy,$orderBy);					$sqlResult = $this->handlerInstance[$this->lastHandlerKey]->_Execute($this->lastQuery);				}				$sqlResult->TYPO3_DBAL_handlerType = 'adodb';	// Setting handler type in result object (for later recognition!)				$sqlResult->TYPO3_DBAL_tableList = $ORIG_tableName;				break;			case 'userdefined':				$sqlResult = $this->handlerInstance[$this->lastHandlerKey]->exec_SELECTquery($select_fields,$from_table,$where_clause,$groupBy,$orderBy,$limit);				if (is_object($sqlResult))	{					$sqlResult->TYPO3_DBAL_handlerType = 'userdefined';	// Setting handler type in result object (for later recognition!)					$sqlResult->TYPO3_DBAL_tableList = $ORIG_tableName;				}				break;		}		if ($this->printErrors && $this->sql_error())	{			debug(array($this->lastQuery, $this->sql_error()));		}		if ($this->debug)	{			$this->debugHandler(				'exec_SELECTquery',				t3lib_div::milliseconds()-$pt,				array(					'handlerType' => $hType,					'args' => array($from_table,$select_fields,$where_clause,$groupBy,$orderBy,$limit),					'ORIG_from_table' => $ORIG_tableName				)			);		}			// Return result handler.		return $sqlResult;	}	/**************************************	*	* Query building	*	**************************************/	/**	 * Creates an INSERT SQL-statement for $table from the array with field/value pairs $fields_values.	 * Usage count/core: 4	 *	 * @param	string		See exec_INSERTquery()	 * @param	array		See exec_INSERTquery()	 * @param mixed		See exec_INSERTquery()	 * @return	mixed		Full SQL query for INSERT as string or array (unless $fields_values does not contain any elements in which case it will be false). If BLOB fields will be affected and one is not running the native type, an array will be returned, where 0 => plain SQL, 1 => fieldname/value pairs of BLOB fields	 * @deprecated			use exec_INSERTquery() instead if possible!	 */	function INSERTquery($table,$fields_values,$no_quote_fields='')	{		// Table and fieldnames should be "SQL-injection-safe" when supplied to this function (contrary to values in the arrays which may be insecure).		if (is_array($fields_values) && count($fields_values))	{			if (is_string($no_quote_fields))        {				$no_quote_fields = explode(',',$no_quote_fields);			} elseif (!is_array($no_quote_fields))  {				$no_quote_fields = array();			}			$blobfields = array();			$nArr = array();			foreach($fields_values as $k => $v)	{				if(!$this->runningNative() && $this->sql_field_metatype($table,$k) == 'B') {						// we skip the field in the regular INSERT statement, it is only in blobfields					$blobfields[$this->quoteFieldNames($k)] = $v;				}				else {					// Add slashes old-school:					// cast numerical values					$mt = $this->sql_field_metatype($table,$k);					$v = (($mt{0}=='I')||($mt{0}=='F')) ? (int)$v : $v;					$nArr[$this->quoteFieldNames($k)] = (!in_array($k,$no_quote_fields)) ? $this->fullQuoteStr($v, $table) : $v;				}			}			if(count($blobfields)) {				if(count($nArr)) {					$query[0] = 'INSERT INTO '.$this->quoteFromTables($table).'					(						'.implode(',						',array_keys($nArr)).'					) VALUES (						'.implode(',						',$nArr).'					)';				}				$query[1] = $blobfields;				if ($this->debugOutput || $this->store_lastBuiltQuery) $this->debug_lastBuiltQuery = $query[0];

⌨️ 快捷键说明

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