The example in this article describes the connection Mysql class and usage encapsulated by PHP. Share it with everyone for your reference, the details are as follows:
class mysql{ private $db_name; private $db_host; private $db_user; private $db_pwd; private $conn; private $querysql; private $result; private $resultarray=array(); private $row; //創(chuàng)建構(gòu)造函數(shù) 數(shù)據(jù)庫名 主機名 用戶名 密碼 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(); } //連接數(shù)據(jù)庫 private function db_connect(){ $this->conn=mysql_connect($this->db_host,$this->db_user,$this->db_pwd) or die("Could not Connect MySql Server"); } private function selectdb(){ mysql_select_db($this->db_name) or die("unable to select dbname") } private function query(){ 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()和 mysql_fetch_array(,MYSQL_ASSOC)從結(jié)果集中取得一行作為關(guān)聯(lián)數(shù)組 沒有則返回false while($this->rows=mysql_fetch_array($this->result)){ //賦值 數(shù)組賦值 resultarray[]= 將影響的行數(shù)賦值給數(shù)組 $this->resultarray[]=$this->rows } return $this->resultarray; } } //$result返回值為 bool類型 false為沒有數(shù)據(jù) private function get_num(){ return $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 be helpful to everyone in php programming design.
For more articles related to PHP encapsulated connection Mysql class and usage analysis, please pay attention to the PHP Chinese website!

Hot AI Tools

Undress AI Tool
Undress images for free

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)