//Database processing class class db { //Data storage variable after SQL execution; var $db; //Read or set the position of the current data var $position=0; //Execute the SQL statement and save the result as a db variable; function sub_sql($str) { global $prefix;//Global function, table prefix return str_replace("dede_",$prefix,$str); } function Sql($str) { $str=$this->sub_sql($str); > while($row = mysql_fetch_array($result)) if(empty($str_array)) $str_array= One bit, if the data is empty, it returns null; function Get_One() { $re=empty($this->db[$this->position])?null:$ this->db[$this->position]; $this->position=$re?$this->position+1:$this->position; } //Judge whether the data has been read to the end function Judge() { $re=empty($this->db[$this->position] )?true:false; return $re; db); } //Update the data in the database, $t is the table name, $v format is the array format, the superscript is the field name, and the subscript is the data; $w is the condition and the superscript is the field The subscript is data, $p is the condition, 0 is the equal sign, 1 is greater than, -1 is less than; function Set_Updata($t,$v,$w,$p=0) { $this->Sql($t); >$vaule) If(!is_numeric($key)) $v_str=htmlspecialchars($key : htmlspecialchars($vaule)."'"; 0: $f="="; break; break; case -1: $f="<"; break; } if(!empty($f)) { foreach($w as $key=>$vaule) { if(!is_numeric($key)) { if(empty($v_str)) { $w_str=htmlspecialchars($key).$f.htmlspecialchars($vaule)."'"; }else { $w_str=$w_str.",".htmlspecialchars($key).$f.htmlspecialchars($vaule)."'"; } } } } $sql="UPDATE ".$t." SET ".$v_str." where ".$w_str; return $result = mysql_query($sql); } //删除一数据$w为条件上标为字段名下标为数据,$p为条件0为等号,1为大于,-1为小于; function Set_Del($t,$w,$p=0) { $this->sub_sql($t); $w_str=""; $f=""; switch($p) { case 0: $f="="; break; case 1: $f=">"; break; case -1: $f="<"; break; } if(!empty($f)) { foreach($w as $key=>$vaule) { if(!is_numeric($key)) { if(empty($v_str)) { $w_str=htmlspecialchars($key).$f.htmlspecialchars($vaule)."'"; }else { $w_str=$w_str.",".htmlspecialchars($key).$f.htmlspecialchars($vaule)."'"; } } } } $str="DELETE FROM ".$t." WHERE ".$w_str; return $result = mysql_query($str); } function Add($t,$v) { $this->sub_sql($t); $k_str=""; $v_str=""; foreach($v as $key=>$vaule) { if(!is_numeric($key)){ if(empty($k_str)) { $k_str=htmlspecialchars($key); $v_str="'".htmlspecialchars($vaule)."'"; }else { $k_str=$k_str.",".htmlspecialchars($key); $v_str=$v_str.","."'".htmlspecialchars($vaule)."'"; } } } $str="INSERT INTO ".$t."(".$k_str.")"."value(".$v_str.")"; return $result = mysql_query($str); } } ?> |