数据访问类封装

<?php
class Wxk
{
	public $host="localhost";
	public $uid="root";
	public $pwd="123";
	public $dbname="Wxk";
	//执行SQL语句返回相应的结果
	//$sql 要执行的SQL语句
	//$type 代表SQL语句的类型,0代表增删改 1代表查询
	function query($sql,$type=1)
			{
				$db= new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname);
				$result= $db -> query($sql);
				if($type)
				{	
					//如果是查询,返回数据
					return $result->fetch_all();
				}
				else
				{
					//如果是增删改,返回true或false
					return $result;
				}
			}
		
	function strquery($sql,$type=1)
		{
			$db= new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname);
			$arry= $db -> query($sql);
			$arr =$arry->fetch_all();
			$str = "";//定义一个空的字符串
			foreach($arr as $v)
			{
				$str = $str.implode("-",$v)."|";//数组拼接字符串
			}
			$result = substr($str,0,strlen($str)-1);//删除多余的“|”
			return $result;//返回字符串
		}
}
原文地址:https://www.cnblogs.com/yi11/p/6854808.html