function DB(){
$this->values = array();
}//DB
function connect() {
$this->conn_id = mysql_connect(SQL_HOST, SQL_USER, SQL_PASS,1);
mysql_select_db(SQL_DB,$this->conn_id);
$version = $this->version();
if($version >= 4.1){
$encoding = extract_encoding("mysql");
if($encoding){
$sql_query = "SET NAMES '".$encoding."'";
$this->execute($sql_query);
}//if
}//if
}//connect
function disconnect(){
if($this->conn_id)
@mysql_close($this->conn_id);
}//disconnect
function version(){
$sql_query = "SELECT VERSION()";
$version = $this->single($sql_query);
$version = ereg_replace("[^0-9|\.]","",$version);
return $version;
}//version
function execute($sql_query) {
if(!$this->conn_id){
$this->connect();
}//if
preg_match_all("/\:[A-Za-z|0-9|_]{1,}\:/",$sql_query,$matches);
$patterns = $matches[0];
while(list(,$val) = each($patterns)){
$key = substr($val,1,strlen($val)-2);
$value = stripslashes($this->values[$key]);
$sql_query = hs_ereg_replace($val,mysql_escape_string($value),$sql_query);
}//while
reset($this->values);
$this->sql_result = mysql_query($sql_query,$this->conn_id);
if(!$this->sql_result && !hs_ereg("^LOCK TABLES",$sql_query) && $sql_query!="UNLOCK TABLES"){
die($sql_query.":".mysql_error($this->conn_id));
}//if
return $this->sql_result;
}//execute
function insert($sql_query){
if((!$this->sql_result)||($sql_query != $this->sql_query)){
$this->execute($sql_query);
}//if
$this->clean();
return mysql_insert_id($this->conn_id);
}//insert
function update($sql_query){
if((!$this->sql_result)||($sql_query != $this->sql_query)){
$this->execute($sql_query);
}//if
$this->clean();
return mysql_affected_rows($this->conn_id);
}//update
function fetch($sql_query){
if((!$this->sql_result)||($sql_query != $this->sql_query)){
$this->execute($sql_query);
}//if
$this->sql_query = $sql_query;
$result = @mysql_fetch_object($this->sql_result);
if(!$result)
$this->clean();
return $result;
}//fetch
function row($sql_query){
if((!$this->sql_result)||($sql_query != $this->sql_query)){
$this->execute($sql_query);
}//if
$this->sql_query = $sql_query;
$result = @mysql_fetch_assoc($this->sql_result);
if(!$result)
$this->clean();
return $result;
}//row
function result($sql_query){
$ret_array = array();
while($this->res = $this->row($sql_query)){
$ret_array[] = $this->res;
}//while
@mysql_free_result($this->res);
$this->clean();
return $ret_array;
}//result
function single($sql_query){
$this->execute($sql_query);
$this->clean();
return @mysql_result($this->sql_result,0);
}//single
function lock($table){
$sql_query="LOCK TABLES `".$table."` WRITE";
$this->execute($sql_query);
}//lock
function unlock(){
$sql_query="UNLOCK TABLES";
$this->execute($sql_query);
}//unlock
function clean(){
$this->sql_query = "";
}//clean
}//DB class
Warm Regards,
Amir