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

📄 class.ux_t3lib_db.php

📁 Typo3, 开源里边最强大的
💻 PHP
📖 第 1 页 / 共 5 页
字号:
	/**	 * Get the type of the specified field in a result	 *	 * If the first parameter is a string, it is used as table name for the lookup.	 *	 * @param	pointer		MySQL result pointer (of SELECT query) / DBAL object / table name	 * @param	integer		Field index. In case of ADOdb a string (field name!) FIXME	 * @return	string		Returns the type of the specified field index	 */	function sql_field_type(&$res,$pointer)	{		if($res === null) {			debug(array('no res in sql_field_type!'));			return 'text';		}		else if(is_string($res)){			if($res == 'tx_dbal_debuglog') return 'text';			$handlerType = 'adodb';		}		else {			$handlerType = is_object($res) ? $res->TYPO3_DBAL_handlerType :  'native';		}		switch($handlerType)	{			case 'native':				$output = mysql_field_type($res,$pointer);				break;			case 'adodb':				if(is_string($pointer)){					$output = $this->cache_fieldType[$res][$pointer]['type'];				}				break;			case 'userdefined':				$output = $res->sql_field_type($pointer);				break;		}		return $output;	}	/**********	*	* Legacy functions, bound to _DEFAULT handler. (Overriding parent methods)	* Deprecated.	*	**********/	/**	 * Executes query (on DEFAULT handler!)	 * DEPRECATED - use exec_* functions from this class instead!	 *	 * @param	string		Database name	 * @param	string		Query to execute	 * @return	pointer		Result pointer	 * @deprecated	 */	function sql($db,$query)	{		return $this->sql_query($query);	}	/**	 * Executes query (on DEFAULT handler!)	 * DEPRECATED - use exec_* functions from this class instead!	 *	 * If you don't, anything that uses not the _DEFAULT handler will break!	 *	 * @param	string		Query to execute	 * @return	pointer		Result pointer / DBAL object	 * @deprecated	 */	function sql_query($query)	{		switch($this->handlerCfg['_DEFAULT']['type'])	{			case 'native':				$sqlResult = mysql_query($query, $this->handlerInstance['_DEFAULT']['link']);				break;			case 'adodb':				$sqlResult = $this->handlerInstance['_DEFAULT']->Execute($query);				$sqlResult->TYPO3_DBAL_handlerType = 'adodb';				break;			case 'userdefined':				$sqlResult = $this->handlerInstance['_DEFAULT']->sql_query($query);				$sqlResult->TYPO3_DBAL_handlerType = 'userdefined';				break;		}		if ($this->printErrors && $this->sql_error())	{			debug(array($this->lastQuery, $this->sql_error()));		}		return $sqlResult;	}	/**	 * Opening the _DEFAULT connection handler to the database.	 * This is typically done by the scripts "init.php" in the backend or "index_ts.php" in the frontend (tslib_fe->connectToMySQL())	 * You wouldn't need to use this at any time - let TYPO3 core handle this.	 *	 * @param	string		Database host IP/domain	 * @param	string		Username to connect with.	 * @param	string		Password to connect with.	 * @return	mixed		Returns handler connection value	 * @deprecated	 * @see handler_init()	 */	function sql_pconnect($TYPO3_db_host, $TYPO3_db_username, $TYPO3_db_password)	{		// Overriding the _DEFAULT handler configuration of username, password, localhost and database name:		$this->handlerCfg['_DEFAULT']['config']['username'] = $TYPO3_db_username;		$this->handlerCfg['_DEFAULT']['config']['password'] = $TYPO3_db_password;		$this->handlerCfg['_DEFAULT']['config']['host'] = $TYPO3_db_host;		$this->handlerCfg['_DEFAULT']['config']['database'] = TYPO3_db;		// Initializing and output value:		$sqlResult = $this->handler_init('_DEFAULT');		return $sqlResult;	}	/**	 * Select database for _DEFAULT handler.	 *	 * @param	string		Database to connect to.	 * @return	boolean		Always returns true; function is obsolete, database selection is made in handler_init() function!	 * @deprecated	 */	function sql_select_db($TYPO3_db)	{		return TRUE;	}	/**************************************	*	* SQL admin functions	* (For use in the Install Tool and Extension Manager)	*	**************************************/	/**	 * Listing databases from current MySQL connection. NOTICE: It WILL try to select those databases and thus break selection of current database.	 * Use in Install Tool only!	 * Usage count/core: 1	 *	 * @return	array		Each entry represents a database name	 */	function admin_get_dbs()	{		$dbArr = array();		switch($this->handlerCfg['_DEFAULT']['type'])	{			case 'native':				$db_list = mysql_list_dbs($this->link);				while ($row = mysql_fetch_object($db_list)) {					if ($this->sql_select_db($row->Database))	{						$dbArr[] = $row->Database;					}				}				break;			case 'adodb':					// check needed for install tool - otherwise it will just die because the call to					// MetaDatabases is done on a stdClass instance				if(method_exists($this->handlerInstance['_DEFAULT'],'MetaDatabases')) {					$sqlDBs = $this->handlerInstance['_DEFAULT']->MetaDatabases();					if(is_array($sqlDBs)) {						foreach($sqlDBs as $k => $theDB) {							$dbArr[] = $theDB;						}					}				}				break;			case 'userdefined':				$dbArr = $this->handlerInstance['_DEFAULT']->admin_get_tables();				break;		}		return $dbArr;	}	/**	 * Returns the list of tables from the system (quering the DBMSs)	 * It looks up all tables from the DBMS of the _DEFAULT handler and then add all tables *configured* to be managed by other handlers	 *	 * When fetching the tables, it skips tables whose names begin with BIN$, as this is taken as a table coming from the "Recycle Bin" on Oracle.	 *	 * @return	array		Tables in an array (tablename is in both key and value)	 * @todo Should the check for Oracle Recycle Bin stuff be moved elsewhere?	 */	function admin_get_tables()	{		$whichTables = array();		// Getting real list of tables:		switch($this->handlerCfg['_DEFAULT']['type'])	{			case 'native':				$tables_result = mysql_list_tables(TYPO3_db, $this->handlerInstance['_DEFAULT']['link']);				if (!$this->sql_error())	{					while ($theTable = $this->sql_fetch_assoc($tables_result)) {						$whichTables[current($theTable)] = current($theTable);					}				}				break;			case 'adodb':				$sqlTables = $this->handlerInstance['_DEFAULT']->MetaTables('TABLES');				while (list($k, $theTable) = each($sqlTables)) {					if(preg_match('/BIN\$/', $theTable)) continue; // skip tables from the Oracle 10 Recycle Bin					$whichTables[$theTable] = $theTable;				}				break;			case 'userdefined':				$whichTables = $this->handlerInstance['_DEFAULT']->admin_get_tables();				break;		}		// Check mapping:		if (is_array($this->mapping) && count($this->mapping))	{			// Mapping table names in reverse, first getting list of real table names:			$tMap = array();			foreach($this->mapping as $tN => $tMapInfo)	{				if (isset($tMapInfo['mapTableName']))	$tMap[$tMapInfo['mapTableName']]=$tN;			}			// Do mapping:			$newList=array();			foreach($whichTables as $tN)	{				if (isset($tMap[$tN]))	$tN = $tMap[$tN];				$newList[$tN] = $tN;			}			$whichTables = $newList;		}		// Adding tables configured to reside in other DBMS (handler by other handlers than the default):		if (is_array($this->table2handlerKeys))	{			foreach($this->table2handlerKeys as $key => $handlerKey)	{				$whichTables[$key] = $key;			}		}		return $whichTables;	}	/**	 * Returns information about each field in the $table (quering the DBMS)	 * In a DBAL this should look up the right handler for the table and return compatible information	 * This function is important not only for the Install Tool but probably for DBALs as well since they might need to look up table specific information in order to construct correct queries. In such cases this information should probably be cached for quick delivery	 *	 * @param	string		Table name	 * @return	array		Field information in an associative array with fieldname => field row	 */	function admin_get_fields($tableName)	{		$output = array();		// Do field mapping if needed:		$ORIG_tableName = $tableName;		if ($tableArray = $this->map_needMapping($tableName))	{			// Table name:			if ($this->mapping[$tableName]['mapTableName'])	{				$tableName = $this->mapping[$tableName]['mapTableName'];			}		}		// Find columns		$this->lastHandlerKey = $this->handler_getFromTableList($ORIG_tableName);		switch((string)$this->handlerCfg[$this->lastHandlerKey]['type'])	{			case 'native':				$columns_res = mysql_query('SHOW columns FROM '.$tableName, $this->handlerInstance[$this->lastHandlerKey]['link']);				while($fieldRow = mysql_fetch_assoc($columns_res))	{					$output[$fieldRow['Field']] = $fieldRow;				}				break;			case 'adodb':				$fieldRows = $this->handlerInstance[$this->lastHandlerKey]->MetaColumns($tableName, false);				foreach($fieldRows as $k => $fieldRow) {					settype($fieldRow, 'array');					$fieldRow['Field'] = $fieldRow['name'];					$ntype = $this->MySQLActualType($this->MetaType($fieldRow['type'],$tableName));					$ntype .= (($fieldRow['max_length'] != -1) ? (($ntype == 'INT') ? '(11)' :'('.$fieldRow['max_length'].')') : '');					$fieldRow['Type'] = strtolower($ntype);					$fieldRow['Null'] = '';					$fieldRow['Key'] = '';					$fieldRow['Default'] = $fieldRow['default_value'];					$fieldRow['Extra'] = '';					$output[$fieldRow['name']] = $fieldRow;				}				break;			case 'userdefined':				$output = $this->handlerInstance[$this->lastHandlerKey]->admin_get_fields($tableName);				break;		}		// mapping should be done:		if (is_array($tableArray) && is_array($this->mapping[$ORIG_tableName]['mapFieldNames']))	{			$revFields = array_flip($this->mapping[$ORIG_tableName]['mapFieldNames']);			$newOutput = array();			foreach($output as $fN => $fInfo)	{				if (isset($revFields[$fN]))	{					$fN = $revFields[$fN];					$fInfo['Field'] = $fN;				}				$newOutput[$fN] = $fInfo;			}			$output = $newOutput;		}		return $output;	}	/**	 * Returns information about each index key in the $table (quering the DBMS)	 * In a DBAL this should look up the right handler for the table and return compatible information	 *	 * @param	string		Table name	 * @return	array		Key information in a numeric array	 */	function admin_get_keys($tableName)	{		$output = array();		// Do field mapping if needed:		$ORIG_tableName = $tableName;		if ($tableArray = $this->map_needMapping($tableName))	{			// Table name:			if ($this->mapping[$tableName]['mapTableName'])	{				$tableName = $this->mapping[$tableName]['mapTableName'];			}		}		// Find columns		$this->lastHandlerKey = $this->handler_getFromTableList($ORIG_tableName);		switch((string)$this->handlerCfg[$this->lastHandlerKey]['type'])	{			case 'native':			$keyRes = mysql_query('SHOW keys FROM '.$tableName, $this->handlerInstance[$this->lastHandlerKey]['link']);			while($keyRow = mysql_fetch_assoc($keyRes))	{				$output[] = $keyRow;			}			break;			case 'adodb':			$keyR

⌨️ 快捷键说明

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