首页 > 代码库 > 数据访问类封装
数据访问类封装
<?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;//返回字符串 } }
数据访问类封装
声明:以上内容来自用户投稿及互联网公开渠道收集整理发布,本网站不拥有所有权,未作人工编辑处理,也不承担相关法律责任,若内容有误或涉及侵权可进行投诉: 投诉/举报 工作人员会在5个工作日内联系你,一经查实,本站将立刻删除涉嫌侵权内容。