[PHP] MySQL Class
<?php
class MySQL{
private $MySQL_Link = null;
public $MySQL_QueryCount = 0;
public $MySQL_QueryID;
private $MySQL_Host;
private $MySQL_Username;
private $MySQL_Password;
private $MySQL_Database;
/* MySQL Class Construct */
function __construct($Host, $Username, $Password, $Database){
$this->MySQL_Host = $Host;
$this->MySQL_Username = $Username;
$this->MySQL_Password = $Password;
$this->MySQL_Database = $Database;
}
/* MySQL Class Destruction */
function __destruct(){
$this->Close();
unset($this->MySQL_Link);
unset($this->MySQL_QueryCount);
unset($this->MySQL_QueryID);
unset($this->MySQL_Host);
unset($this->MySQL_Username);
unset($this->MySQL_Password);
unset($this->MySQL_Database);
unset($this);
}
/* MySQL Connection */
public function Connect($Username=false, $Password=false, $Database=false){
if($this->MySQL_Link == null && $Username && $Password){
$this->MySQL_Username = $Username;
$this->MySQL_Password = $Password;
if($Database){
$this->MySQL_Database = $Database;
}
@mysql_change_user($this->MySQL_Username, $this->MySQL_Password, $this->MySQL_Database, $this->MySQL_Link);
@end();
}else if($this->MySQL_Link == null && $Username && $Password){
$this->MySQL_Username = $Username;
$this->MySQL_Password = $Password;
if($Database){
$this->MySQL_Database = $Database;
}
}
if($this->MySQL_Link == null){
$this->MySQL_Link = @mysql_connect($this->MySQL_Host, $this->MySQL_Username, $this->MySQL_Password, true, MYSQL_CLIENT_COMPRESS);
if(!$this->MySQL_Link){
$this->MySQL_Link = null;
}else{
if(@mysql_select_db($this->MySQL_Database, $this->MySQL_Link)){
return true;
}
return false;
}
}
if($this->MySQL_Link){
return true;
}else{
die();
}
}
/* MySQL Query */
public function Query($Sql){
$this->MySQL_QueryCount++;
$this->MySQL_QueryID = @mysql_query($Sql, $this->MySQL_Link);
if($this->MySQL_QueryID !== false){
return $this->MySQL_QueryID;
}
return false;
}
/* MySQL Result */
public function Result($QueryID=null, $Row=0, $Field=null){
if($QueryID == null){ $QueryID = $this->MySQL_QueryID; }
if($Field != null){
return @mysql_result($QueryID, $Row, $Field);
}
return @mysql_result($QueryID, $Row);
}
/* MySQL Fetch Array */
public function Fetch_Array($QueryID=null, $ResultType=MYSQL_ASSOC){
if($QueryID == null){ $QueryID = $this->MySQL_QueryID; }
return @mysql_fetch_array($QueryID, $ResultType);
}
/* MySQL Fetch Array */
public function Free_Result($QueryID=null){
if($QueryID == null){ $QueryID = $this->MySQL_QueryID; }
return @mysql_free_result($QueryID);
}
/* MySQL POST/GET Escape */
public function RequestEscape(){
global $_REQUEST;
foreach ($_REQUEST as $Key => $Value) {
$_REQUEST[$Key] = mysql_real_escape_string($Value);
}
}
/* MySQL Escape */
public function Escape($String){
return mysql_real_escape_string($String, $this->MySQL_Link);
}
/* MySQL Close */
public function Close(){
if($this->MySQL_Link != null && $this->MySQL_Link == true){
@mysql_close($this->MySQL_Link);
$this->MySQL_Link = null;
}
}
}
?>