<?php
class cls_base_table
{
	private $obj_db;
	function __construct()
	{
		global $obj_db;
		$this->obj_db=$obj_db;
	}
	protected function on_insert($msg_table,$arr_fields)
	{
		$arr_return=array("err"=>"","id"=>0);
		if(!is_array($arr_fields))
		{
			$arr_return["err"]="插入数据字段与值不同!";
			return $arr_return;
		}
		$str_fields="";
		$str_values="";
		foreach($arr_fields as $item=>$key)
		{
			$str_fields.=$item.",";
			$str_values.="'".mysql_real_escape_string($key)."',";
		}
		$str_fields=substr($str_fields,0,-1);
		$str_values=substr($str_values,0,-1);
		$str_sql="insert into ".$msg_table."(".$str_fields.") values(".$str_values.")";
		$arr_return["err"]=$this->obj_db->execute($str_sql);
		if($arr_return["err"]!=""){
			$arr_return["err"].="<br>".$this->obj_db->error();
		}else{
			$arr_return["id"]=$this->obj_db->insert_id();
		}
		return $arr_return;
	}
	protected function on_update($msg_table,$arr_fields,$msg_where)
	{
		$arr_return=array();
		if(!is_array($arr_fields))
		{
			return "更新数据字段与值不同!";
		}
		$str_x="";
		foreach($arr_fields as $item=>$key)
		{
			$str_x.=$item."='".mysql_real_escape_string($key)."',";
		}
		$str_x=substr($str_x,0,-1);
		$str_sql="update ".$msg_table." set ".$str_x." where ".$msg_where;
		$arr_return["err"]=$this->obj_db->execute($str_sql);
		return $arr_return;
	}
	protected function on_del($msg_table,$msg_where)
	{
		$arr_return=array();
		$str_sql="delete from ".$msg_table." where ".$msg_where;
		$arr_return["err"]=$this->obj_db->execute($str_sql);
		return $arr_return;
	}
}
?>