class db_mysql{
public $link,$key,$values,$error,$return;
function __construct($host,$user,$pw,$db,$encode){
$this->connect($host,$user,$pw,$db,$encode);
}
function __destruct(){
if (is_resource($this->link)){
mysql_close($this->link);
}
}
function connect($host,$user,$pw,$db,$encode){
if (!$this->link = @mysql_connect($host,$user,$pw)){
$this->error = mysql_error();
}
if (!@mysql_select_db($db,$this->link)){
$this->error = 'Unknown MySQL database /''.$db.'/'';
}
if (!@mysql_query("SET NAMES '".$encode."'",$this->link)){
$this->error = mysql_error();
}
}
function query($sql){
$result = mysql_query($sql,$this->link);
if (is_resource($result)){
$this->return = array();
while($tmp = mysql_fetch_array($result)){
$this->return[] = $tmp;
}
}
else {
$this->return = $result;
}
}
function format($arr){
$len = sizeof($arr);
for($i=0;$i
$tmp = each($arr);
$mark = $i !== $len-1 ? ',' : NULL;
$this->keys .= $tmp['key'].$mark;
$this->values .= '"'.mysql_real_escape_string($tmp['value']).'"'.$mark;
}
}
}