我的DBDA类文件

<?php
class DBDA
{
    public $host = "localhost";
    public $uid = "root";
    public $pwd = "root";
    public $dbname = "mydb";
    
    public function Query($sql,$type=1)
    {
        $db = new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname);
        $result = $db->query($sql);
        
        if($type=="1")
        {
            return $result->fetch_all();
        }
        else
        {
            return $result;
        }
    }
    
    public function StrQuery($sql,$type=1)
    {
        $db = new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname);
        $result = $db->query($sql);
        
        if($type=="1")
        {
            $arr = $result->fetch_all();
            $str = "";
            foreach($arr as $v)
            {
                $str = $str.implode("^",$v)."|";
            }
            $str = substr($str,0,strlen($str)-1);
            return  $str;
        }
        else
        {
            return $result;
        }
    }
    
    public function JsonQuery($sql,$type=1)
    {
        $db = new MySQLi($this->host,$this->uid,$this->pwd,$this->dbname);
        $result = $db->query($sql);
        
        if($type=="1")
        {
            $arr = $result->fetch_all(MYSQLI_ASSOC);
            return json_encode($arr);
        }
        else
        {
            return $result;
        }
    }
}

 

posted @ 2017-05-02 10:06  ▍凉城空巷°  阅读(128)  评论(0编辑  收藏  举报