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

📄 mysql.php

📁 Joomla!是一套获得过多个奖项的内容管理系统(Content Management System, CMS)。Joomla!采用PHP+MySQL数据库开发
💻 PHP
📖 第 1 页 / 共 2 页
字号:
	 * This method loads the first field of the first row returned by the query.	 *	 * @access	public	 * @return The value returned in the query or null if the query failed.	 */	function loadResult()	{		if (!($cur = $this->query())) {			return null;		}		$ret = null;		if ($row = mysql_fetch_row( $cur )) {			$ret = $row[0];		}		mysql_free_result( $cur );		return $ret;	}	/**	 * Load an array of single field results into an array	 *	 * @access	public	 */	function loadResultArray($numinarray = 0)	{		if (!($cur = $this->query())) {			return null;		}		$array = array();		while ($row = mysql_fetch_row( $cur )) {			$array[] = $row[$numinarray];		}		mysql_free_result( $cur );		return $array;	}	/**	* Fetch a result row as an associative array	*	* @access	public	* @return array	*/	function loadAssoc()	{		if (!($cur = $this->query())) {			return null;		}		$ret = null;		if ($array = mysql_fetch_assoc( $cur )) {			$ret = $array;		}		mysql_free_result( $cur );		return $ret;	}	/**	* Load a assoc list of database rows	*	* @access	public	* @param string The field name of a primary key	* @return array If <var>key</var> is empty as sequential list of returned records.	*/	function loadAssocList( $key='' )	{		if (!($cur = $this->query())) {			return null;		}		$array = array();		while ($row = mysql_fetch_assoc( $cur )) {			if ($key) {				$array[$row[$key]] = $row;			} else {				$array[] = $row;			}		}		mysql_free_result( $cur );		return $array;	}	/**	* This global function loads the first row of a query into an object	*	* @access	public	* @return 	object	*/	function loadObject( )	{		if (!($cur = $this->query())) {			return null;		}		$ret = null;		if ($object = mysql_fetch_object( $cur )) {			$ret = $object;		}		mysql_free_result( $cur );		return $ret;	}	/**	* Load a list of database objects	*	* If <var>key</var> is not empty then the returned array is indexed by the value	* the database key.  Returns <var>null</var> if the query fails.	*	* @access	public	* @param string The field name of a primary key	* @return array If <var>key</var> is empty as sequential list of returned records.	*/	function loadObjectList( $key='' )	{		if (!($cur = $this->query())) {			return null;		}		$array = array();		while ($row = mysql_fetch_object( $cur )) {			if ($key) {				$array[$row->$key] = $row;			} else {				$array[] = $row;			}		}		mysql_free_result( $cur );		return $array;	}	/**	 * Description	 *	 * @access	public	 * @return The first row of the query.	 */	function loadRow()	{		if (!($cur = $this->query())) {			return null;		}		$ret = null;		if ($row = mysql_fetch_row( $cur )) {			$ret = $row;		}		mysql_free_result( $cur );		return $ret;	}	/**	* Load a list of database rows (numeric column indexing)	*	* @access public	* @param string The field name of a primary key	* @return array If <var>key</var> is empty as sequential list of returned records.	* If <var>key</var> is not empty then the returned array is indexed by the value	* the database key.  Returns <var>null</var> if the query fails.	*/	function loadRowList( $key=null )	{		if (!($cur = $this->query())) {			return null;		}		$array = array();		while ($row = mysql_fetch_row( $cur )) {			if ($key !== null) {				$array[$row[$key]] = $row;			} else {				$array[] = $row;			}		}		mysql_free_result( $cur );		return $array;	}	/**	 * Inserts a row into a table based on an objects properties	 *	 * @access	public	 * @param	string	The name of the table	 * @param	object	An object whose properties match table fields	 * @param	string	The name of the primary key. If provided the object property is updated.	 */	function insertObject( $table, &$object, $keyName = NULL )	{		$fmtsql = 'INSERT INTO '.$this->nameQuote($table).' ( %s ) VALUES ( %s ) ';		$fields = array();		foreach (get_object_vars( $object ) as $k => $v) {			if (is_array($v) or is_object($v) or $v === NULL) {				continue;			}			if ($k[0] == '_') { // internal field				continue;			}			$fields[] = $this->nameQuote( $k );			$values[] = $this->isQuoted( $k ) ? $this->Quote( $v ) : (int) $v;		}		$this->setQuery( sprintf( $fmtsql, implode( ",", $fields ) ,  implode( ",", $values ) ) );		if (!$this->query()) {			return false;		}		$id = $this->insertid();		if ($keyName && $id) {			$object->$keyName = $id;		}		return true;	}	/**	 * Description	 *	 * @access public	 * @param [type] $updateNulls	 */	function updateObject( $table, &$object, $keyName, $updateNulls=true )	{		$fmtsql = 'UPDATE '.$this->nameQuote($table).' SET %s WHERE %s';		$tmp = array();		foreach (get_object_vars( $object ) as $k => $v)		{			if( is_array($v) or is_object($v) or $k[0] == '_' ) { // internal or NA field				continue;			}			if( $k == $keyName ) { // PK not to be updated				$where = $keyName . '=' . $this->Quote( $v );				continue;			}			if ($v === null)			{				if ($updateNulls) {					$val = 'NULL';				} else {					continue;				}			} else {				$val = $this->isQuoted( $k ) ? $this->Quote( $v ) : (int) $v;			}			$tmp[] = $this->nameQuote( $k ) . '=' . $val;		}		$this->setQuery( sprintf( $fmtsql, implode( ",", $tmp ) , $where ) );		return $this->query();	}	/**	 * Description	 *	 * @access public	 */	function insertid()	{		return mysql_insert_id( $this->_resource );	}	/**	 * Description	 *	 * @access public	 */	function getVersion()	{		return mysql_get_server_info( $this->_resource );	}	/**	 * Assumes database collation in use by sampling one text field in one table	 *	 * @access	public	 * @return string Collation in use	 */	function getCollation ()	{		if ( $this->hasUTF() ) {			$this->setQuery( 'SHOW FULL COLUMNS FROM #__content' );			$array = $this->loadAssocList();			return $array['4']['Collation'];		} else {			return "N/A (mySQL < 4.1.2)";		}	}	/**	 * Description	 *	 * @access	public	 * @return array A list of all the tables in the database	 */	function getTableList()	{		$this->setQuery( 'SHOW TABLES' );		return $this->loadResultArray();	}	/**	 * Shows the CREATE TABLE statement that creates the given tables	 *	 * @access	public	 * @param 	array|string 	A table name or a list of table names	 * @return 	array A list the create SQL for the tables	 */	function getTableCreate( $tables )	{		settype($tables, 'array'); //force to array		$result = array();		foreach ($tables as $tblval) {			$this->setQuery( 'SHOW CREATE table ' . $this->getEscaped( $tblval ) );			$rows = $this->loadRowList();			foreach ($rows as $row) {				$result[$tblval] = $row[1];			}		}		return $result;	}	/**	 * Retrieves information about the given tables	 *	 * @access	public	 * @param 	array|string 	A table name or a list of table names	 * @param	boolean			Only return field types, default true	 * @return	array An array of fields by table	 */	function getTableFields( $tables, $typeonly = true )	{		settype($tables, 'array'); //force to array		$result = array();		foreach ($tables as $tblval)		{			$this->setQuery( 'SHOW FIELDS FROM ' . $tblval );			$fields = $this->loadObjectList();			if($typeonly)			{				foreach ($fields as $field) {					$result[$tblval][$field->Field] = preg_replace("/[(0-9)]/",'', $field->Type );				}			}			else			{				foreach ($fields as $field) {					$result[$tblval][$field->Field] = $field;				}			}		}		return $result;	}}

⌨️ 快捷键说明

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