數據訪問類封裝
阿新 • • 發佈:2017-05-15
拼接 brush 數組 訪問 result false bsp oot sql語句
<?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;//返回字符串 } }
數據訪問類封裝