封装对象类

<?php

class DBDA
{
    public $host="localhost";//服务器地址
    public $uid="root";//用户名
    public $pwd="3177389";//用户密码
    
    
    
    
    

public function Query($sql,$type=1,$db="my test")
{
    //造连接对象
    $conn=new MySQLi($this->host,$this->uid,$this->pwd,$db);
    //判断连接是否成功
    !mysqli_connect_error()or die("连接失败!");
    //执行sql语句
    $result=$conn->query($sql);
    //判断语句类型
    if($type==1)
    
    {//如果是查询语句返回结果集的二维数组
        return $result->fetch_all();
        
    }
    else
    {//如果是其他语句,返回true or false
        return $result;
        
    }
}
}

 

posted on 2016-03-27 16:57  宁静致远-zw  阅读(166)  评论(0)    收藏  举报