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

📄 mysql.php

📁 一开始是CPM电脑上的游戏
💻 PHP
字号:
<?php
class sql_driver {
	var $sqlParam = array ( "database"   => ""      ,
							"host"       => ""		,
							"port"       => ""      ,
							"user"       => ""     	,
							"pass"       => ""      ,
					 );        
	 var $queryID      = "";
	 var $ID = "";
				 
	/*=========================Connect to the database.=======================*/
	function connect() {
		$this->ID = mysql_connect( $this->param['sql_host'] ,
			  $this->param['sql_user'] , $this->param['sql_pass']);

		if ( !mysql_select_db($this->param['sql_database'], $this->ID) )
			echo ("Error ".$this->param['sql_database']." cannot be found in the
			database server");
	}
	  
	/*========================Disconnect from the database.===================*/
	function disconnect() {
		return mysql_close($this->ID);
	}
   
	/*=========================Query the Database.============================*/
	function query($inputQuery) {
		$this->queryID = mysql_query($inputQuery, $this->ID);
		if (! $this->queryID )
		{
			echo("SQL error during : $the_query");
			echo(mysql_error());
		}
		return $this->queryID;
	}
   
	/*========================Fetch row from last query.======================*/
	function getRow() {
		return mysql_fetch_array($this->queryID, MYSQL_ASSOC);
	}

	/*========================Get number of affected rows.====================*/
	function affectedRows() {
		return mysql_affected_rows($this->ID);
	}
   
	/*========================Get number of rows in result.===================*/
	function getNumberRows() {
		return mysql_num_rows($this->queryID);
	}
   
	/*========================Get the insert id from the last query.==========*/
	function getInsertID() {
		return mysql_insert_id($this->ID);
	} 

	/*========================Free the result of the query.===================*/
   function freeResult() {
		@mysql_free_result($this->queryID);
	}
	
	/*========================Get Fields in the query.========================*/
	function getResultFields() {
		while ($field = mysql_fetch_field($this->queryID))
			$Fields[] = $field;
		return $Fields;
	}
	
   /*========================Get all tables in database.=====================*/
   function getTableNames() {
		$result     = mysql_list_tables($this->param['sql_database']);
		$num_tables = @mysql_numrows($result);
		for ($i = 0; $i < $num_tables; $i++)
		{
			$tables[] = mysql_tablename($result, $i);
		}
		
		mysql_free_result($result);
		return $tables;
	}
   
	/*=======================Generate string to insert into an array.=========*/
	function generateInsertString($data) {
		$dataTypes  = "";
		$dataValues = "";
		
		foreach ($data as $k => $v) {
			$v = preg_replace( "/'/", "\\'", $v );
			$dataTypes  .= "$k,";
			$dataValues .= "'$v',";
		}
		$dataTypes  = preg_replace( "/,$/" , "" , $dataTypes  );
		$dataValues = preg_replace( "/,$/" , "" , $dataValues );
		
		return array( 'dataNames'  => $dataTypes,
					  'dataValues' => $dataValues,  );
	}
	
	/*======================Generate string to update into an array.==========*/
   function generateUpdateString($data) {
		$return_string = "";
		foreach ($data as $k => $v) {
			$v = preg_replace( "/'/", "\\'", $v );
			$return_string .= $k . "='".$v."',";
		}
		return preg_replace( "/,$/" , "" , $return_string );
	}
}
?>

⌨️ 快捷键说明

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