PHP implementation of the full database operation class, PHP implementation database
In this paper, we describe the database operation class that the PHP implementation compares completely. Share to everyone for your reference. Specific as follows:
<?php class Database {private $hostname; Private $user; Private $pass; Private $dbname; Private $linkflag; Private $charset; function __construct () {$this->hostname= "localhost"; $this->user= "root"; $this->pass= "111"; $this->dbname= ""; $this->charset= "UTF8"; gb2312 GBK UTF8 $this->linkflag=mysql_connect ($this->hostname, $this->user, $this->pass); mysql_select_db ($this->dbname, $this->linkflag) or Die ($this->error ()); mysql_query ("Set names". $this->charset); } function __set ($property _name, $value) {return $this, $property _name= $value; } function __get ($property _name) {if (Isset ($this, $property _name)) {return $this, $property _name; } else return null; } function __call ($function _name, $args) {echo "
The method you are calling $function _name does not exist
\ n "; } function Query ($sql) {$res =mysql_query ($sql) or Die ($this->error ()); return $res; } function Fetch_array ($res) {return mysql_fetch_array ($res); } function Fetch_object ($res) {return mysql_fetch_object ($res); } function Fetch_obj_arr ($sql) {$obj _arr=array (); $res = $this->query ($sql); while ($row =mysql_fetch_object ($res)) {$obj _arr[]= $row; } return $obj _arr; } function error () {if ($this->linkflag) {return mysql_error ($this->linkflag); } else return mysql_error (); } function errno () {if ($this->linkflag) {return Mysql_errno ($this->linkflag); } else return Mysql_errno (); } function Affected_rows () {return mysql_affected_rows ($this->linkflag); } function Num_rows ($sql) {$res = $this->execute ($sql); Return mysql_num_rows ($res); } function Num_fields ($res) {return mysql_num_fields ($res); } function insert_id () {$previous _id=mysql_insert_id ($this->linkflag); return $previous_id; function result ($res, $row, $field =null) {if ($field ===null) {$res =mysql_result ($res, $row); } else $res =mysql_result ($res, $row, $field); return $res; } function version () {return mysql_get_server_info ($this->linkflag); } function Data_seek ($res, $rowNum) {return Mysql_data_seek ($res, $rowNum); } function __destruct () {//mysql_close ($this->linkflag); }}?>
I hope this article is helpful to everyone's PHP programming.
http://www.bkjia.com/PHPjc/1019060.html www.bkjia.com true http://www.bkjia.com/PHPjc/1019060.html techarticle PHP Implementation of the database operation of the whole class, PHP implementation of the database in this case, the implementation of PHP is a complete database operation class. Share to everyone for your reference. The following: Php cla ...