PHP使用类对mysql的使用进行封装
来源:互联网 发布:淘宝卖爱奇艺会员 编辑:程序博客网 时间:2024/06/06 07:05
先前有过文章介绍了PHP中通过普通方法对mysql进行封装使用,回顾可以点击链接查看: PHP中MySQL的连接封装。今天介绍使用类的方法对MySQL进行封装。
具体代码如下:
<?phpheader("content-type:text/html;charset=utf8");//Mysql数据库连接class Mysql{ public $db_host; public $db_user; public $db_pass; public $db_charset; public $db_name; public function __construct($db_host,$db_user,$db_pass,$db_charset,$db_name){ $this->db_host=$db_host; $this->db_user=$db_user; $this->db_pass=$db_pass; $this->db_charset=$db_charset; $this->db_name=$db_name; $this->connect(); } public function connect(){ @mysql_connect($this->db_host,$this->db_user,$this->db_pass); mysql_set_charset($this->db_charset); mysql_select_db($this->db_name); } public function getAll($sql){ $res =mysql_query($sql); $rows=[]; while($row=mysql_fetch_assoc($res)){ $rows[]=$row; } return $rows; } public function __destruct(){ mysql_close(); } }$mysql=new Mysql('127.0.0.1','root','root','utf8','cms');$arr=$mysql->getAll("select *from cms_user");var_dump($arr);?>
阅读全文
0 0
- PHP使用类对mysql的使用进行封装
- 使用PHP调用Mysql数据库函数封装,对数据库进行增删改查
- 使用VBS对FSO对象进行类封装
- Java之使用getXxx()或setXxx对类进行封装
- 对Remoting进行封装,方便使用
- 对MBProgressHUD进行封装并精简使用
- 使用DapperSimpleCRUD对Repository层进行封装
- php+mysql的分页进行封装调用
- PHP---对crud进行封装
- Android对SQLite数据库进行封装使用反射来进行表的增删改查
- 对使用zend加密后的php文件进行解密
- 如何使用强大的PHP函数对数组进行排序
- mysql 5.6 版本,对在使用的表进行分区
- 使用PHP对配置文件进行修改
- 使用PHP对非法内容进行检查
- 使用PHP对配置文件进行修改
- 使用PHP对配置文件进行修改
- 使用PHP对非法内容进行检查
- HDU 3336 Count the string (KMP的nex数组)
- 使用fn标签处理el表达式的值
- JavaScript权威指南学习笔记(一)2
- 开发教程地址
- 谷歌浏览器跨域
- PHP使用类对mysql的使用进行封装
- NOIP2017提高组模拟赛 8(总结)
- 创建Source Insight工程
- Intellij IDEA学习笔记
- RobotStudio仿真—Smart组件创建动态输送链
- Android NDK交叉编译环境的搭建
- jQuery动画---自定义动画animate()
- 操作系统概念(高等教育出版社,第七版)复习——第十章:文件系统接口
- word-wrap 和 word-break 属性