封装接口类

接口类

host = $host;
		 $this->username = $username;
		 $this->pwd = $pwd;
		 $this->db_name = $db_name;
		 $this->charset = $charset;
		 mysql_connect($this->host,$this->username,$this->pwd);
		 mysql_select_db($this->db_name);
		 mysql_query($this->charset);
	}
     //查询单条数据
	public function find($table,$where){
         $sql="select * from $table where $where";
		 $res=mysql_query($sql);
		 $arr=mysql_fetch_assoc($res);
		 return $res;
	 }
	 //查询所有数据
     public function select($table){
         $sql="select * from $table";
		 $res=mysql_query($sql);
		 return $res;
	 }
	 //删除数据
	public function del($table,$where){
         $sql="delete from $table where $where";
		 $res=mysql_query($sql);
		 return $res;
	 }
	}
?>
视图层展示
select('news');
?>
ID 标题 内容 操作
删除

删除
del('news',"id='$id'");
if($arr){
   echo "删除成功";
}else{
  echo "删除失败";
}
?>



你可能感兴趣的:(php)