<?phpclass fengzhuang {public $host="localhost";public $uid="root";public $pwd="159357";public $sjkname="yuheng";//返回二维数组 function query($sql,$type=1){$db = new MySQLi($this->host,$this->uid,$this->pwd,$this->sjkname);$reslut = $db->query($sql);if($type==1){return $reslut->fetch_all();}else{return $reslut;}}//返回关联数组function glquery($sql,$type=1){$db = new MySQLi($this->host,$this->uid,$this->pwd,$this->sjkname);$reslut = $db->query($sql);if($type==1){$attr = array();while($a = $reslut->fetch_assoc()) //取一条 {$attr[] = $a;}return $attr;}else{return $reslut;}}//返回接字符串function strquery($sql,$type=1){$db = new MySQLi($this->host,$this->uid,$this->pwd,$this->sjkname);$reslut = $db->query($sql);if($type=1){$attr = $reslut->fetch_all(); //二维数组不能用implode$str = "";foreach($attr as $v){$str .= implode("^",$v);$str .= "|";}return substr($str,0,strlen($str)-1);}else{return $reslut;}} }
转载于:https://www.cnblogs.com/u1020641/p/6416470.html