PHP-Encapsulated connection MySQL class and usage analysis _php tips

Source: Internet
Author: User
Tags php programming

The examples in this article describe the connection MySQL class and usage in PHP encapsulation. Share to everyone for your reference, specific as follows:

Class mysql{Private $db _name, private $db _host, private $db _user, private $db _pwd, private $conn, private $querysql, PRI
Vate $result;
Private $resultarray =array ();
Private $row; Create constructor database name hostname username password function __counstruct ($dbname, $dbhost, $dbuser, $dbpwd) {$this->db_name= $dbname; $this->
Db_host= $dbhost;
$this->db_pwd= $dbpwd;
$this->db_user= $dbuser;
$this->dbconnect ();
$this->selectdb (); }//Connection database Private function Db_connect () {$this->conn=mysql_connect ($this->db_host, $this->db_user, $this-
>DB_PWD) or die ("could not Connect to MYSQL Server"); Private Function Selectdb () {mysql_select_db ($this->db_name) or Die ("Unable to select DBName")} Private function que Ry () {return $this->result=mysql_query ($this->querysql);} Private Function Get_result ($sql) {$this->
Querysql= $sql;
$this->query ();
if ($this->get_num () >0) {//mysql_fetch_assoc () and mysql_fetch_array (, MYSQL_ASSOC) take one row from the result set as an associative array, return false while ($this->rows=mysql_fetch_array ($this-≫result) {//Assignment array Assignment resultarray[]= the number of rows affected to the array $this->resultarray[]= $this->rows} return $this->
Resultarray;
}//$result The return value is bool type false to no data private function Get_num () {returns $this->num=mysql_num_rows ($this->result);}
$m =new MySQL ("testuser", "localhost", "root", "root");

 $arreresult = $m->get_result ("SELECT * from UserInfo");

I hope this article will help you with your PHP programming.

Related Article

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.