PHP implementation of the full database operation class, PHP implementation of database _php tutorial

Source: Internet
Author: User

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 ...

  • Contact Us

    The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

    If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.