Home >php教程 >PHP源码 >mysqli二次封装 蛋疼 本来就面向对象 又封装了一次

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

PHP中文网
PHP中文网Original
2016-05-25 17:10:211055browse

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();

	 	}


	 } 


?>
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn