php-基于面向对象的MySQL类
2016-07-20 18:20
531 查看
classsqlHelper{ private$conn; private$host='localhost'; private$user='root'; private$pwd='root'; private$db; publicfunction__construct($idb){ $this->db=$idb; $this->conn=newmysqli($this->host,$this->user,$this->$this->pwd,$this->idb); if($this->conn->connect_error){ $this->error($this->conn->connect_error); } $this->conn->query('setnamesutf8'); } //针对select语句 publicfunctionexecute_dql($sql){ $res=$this->conn->query($sql)or$this->error('查询操作失败'.$this->conn->error); $this->free(); return$res; } //针对insert、update、delect publicfunctionexecute_dml($sql){ $flag=$this->conn->query($sql)or$this->error($this->conn->error); if(!$flag){ return0;//操作失败 }else{ if($this->conn->afffected_rows>0){ return1;//操作成功 }else{ return2;//操作失败没有行数受到影响 } } } //针对多行记录 publicfunctionfetch_all($sql){ $res=$this->conn->query($sql)or$this->error('查询操作失败'.$this->conn->error); $arr=array(); while($row=$res->fetch_assoc()){ $arr[]=$row;//及时释放资源 } return$arr; } protectedfunctionerror($err){ $log='cur.log'; file_put_contens($log,$err,FILE_APPEND); die($err); } }
相关文章推荐
- php读取xml对象
- LayoutParams的详解
- php strpos(), stripos(),strrpos(), strripos()的区别
- [matplotlib] 绘制Cross-Validation的误差图
- 【机房收费系统】——子窗体在MDI窗体中最小化(API函数:SetParent())
- ubuntu使用PHP访问Hadoop,利用WebHDFS
- php集成动态口令认证
- PHPMyadmin 配置
- php中的$_SERVER['SERVER_NAME']
- PHP编码规范整理,很全很实用(图文版)
- 功能强大的php分页函数
- PHP查询数据库中表是否存在 方法
- php第一次无法获取cookie问题处理
- php发送get、post请求的6种方法代码示例
- 用php实现一个敏感词过滤功能
- PHP-无限级分类
- PHP转换文本框内容为HTML格式的方法
- PHP 如何查看数据库中数据表是否存在
- PHP中cookie、localStorage、session、的用法
- php如何一起查询多个数据库的所有表?