首页 > php教程 > PHP源码 > 正文

mysqli二次封装 蛋疼 本来就面向对象 又封装了一次

PHP中文网
发布: 2016-05-25 17:10:21
原创
999 人浏览过

php代码:

<?php
	
	//mysqli的DB 类

	/**
	 * 
	 */
	 class MYSQLI{

	 	public $dbhost;		//主机
	 	public $dbuser;		//用户
	 	public $dbpassword;	//密码
	 	public $dbname;		//数据库名称
	 	public $dbport;		//端口号
	 	public $errno;		//错误号
	 	public $error;		//错误内容
	 	
	 	public $mysqli;		//mysqli连接对象句柄
	 	public $query;		//query结果
	 	public $result;		//查询的结果集
	 	public $aff_rows;	//受影响的行数
	 	public $num_rows;	//查询结果条数
	 	
	 	function __construct(){
	 		//连接数据库
	 		$this->mysqli = new mysqli($this->dbhost, $this->dbuser, $this->dbpassword, $this->dbname, $this->dbport);

	 		if($this->mysqli->connect_error){

	 			die(&#39;Connect Error (&#39;.$this->mysqli->connect_errno.&#39;)&#39;.$this->mysqli->connect_error);

	 		}

	 	}

	 	//执行 dml 操作语句
	 	function dml($sql){

	 		$this->query = $this->mysqli->query($sql);

	 	}

	 	//取得受影响的行数
	 	function affected_rows(){

	 		$this->aff_rows = $this->mysqli->affected_rows;

	 	}

	 	//执行 dql 语句
	 	function dql($sql){

	 		$this->result = $this->mysqli->query($sql);

	 	}

	 	//取得查询结果条数
	 	function num_rows(){

	 		$this->num_rows = $this->result->num_rows;

	 	}

	 	//取得查询结果集
	 	function fetch_object(){

	 		//以对象形式返回
	 		return $obj = $this->result->fetch_object();

	 	}


	 } 


?>
登录后复制
来源:php.cn
本站声明
本文内容由网友自发贡献,版权归原作者所有,本站不承担相应法律责任。如您发现有涉嫌抄袭侵权的内容,请联系admin@php.cn
作者最新文章
热门推荐
热门教程
更多>
最新下载
更多>
网站特效
网站源码
网站素材
前端模板
关于我们 免责声明 Sitemap
PHP中文网:公益在线PHP培训,帮助PHP学习者快速成长!