<?php
class DBDA{
	public $host = "localhost";
	public $uid = "root";
	public $pwd = "";
	public $dbname = "lian";
	
	/*
		query方法:执行用户给的SQL语句,并返回相应的结果
		$sql:用户需要执行的SQL语句
		$type:用户需要执行的SQL语句的类型
		return:如果是增删改返回true或false,如果是查询返回二维数组
	*/
	public function query($sql,$type=0){
		$db = new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname);
		if(mysqli_connect_error()){
			return "连接失败!";
		}
		$result = $db->query($sql);
		if($type==0){
			return $result;
		}else{
			return $result->fetch_all();
		}
	}
	
	
	
	
	public function strquery($sql,$type=0){
        	$db = new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname);
			if(mysqli_connect_error()){
				return "连接失败!";
			}
			$result = $db->query($sql);
			if($type==0){
				return $result;
			}else{
				$arr = $result->fetch_all();
				$str="";
				foreach($arr as $v){
					$str = $str.implode("^", $v)."|";
				}
				$str=substr($str,0,strlen($str)-1);
				return $str;
			}
        }
}

  

posted on 2017-09-15 15:48  唯懿  阅读(100)  评论(0编辑  收藏  举报