The Mysqli extension Library is an improved version of the MySQL extension library, which improves stability and efficiency on the basis of the MySQL extension library, and the Mysqli extension Library has two sets of things, one set is the process-oriented mysqli and the other is the object-oriented mysqli. The operation is roughly the same as the MySQL extension library, this time to extract an operation of the MySQL tool class, and the calling class.
1.MYSQLI Extended Library Operations Database Tools class
<?PHP//Database Operations Classes classdbutil{Private $host= "localhost"; Private $username= "Root"; Private $password= "123456"; Private $dbname= "Student"; Private $conn; Public functionDbutil () {$this->conn=NewMysqli ($this->host,$this->username,$this->password,$this->dbname) or die($this->conn->connect_error); } //Enquiry Public functionQuery$sql){ $all=$this->conn->query ($sql); return $all; } //Insert, modify, delete Public functionOtheroperate ($sql){ if($this->conn->query ($sql)){ if($this->conn->affected_rows>0){ return"OK"; }Else{ return"Erroor"; } } } Public functionClose () {$this->conn->Close (); } }?>
2. The following is the code that invokes the tool class
<?PHPrequire_once"Mysqlutil.php"; /*$sql = "SELECT * from M_student"; $util =new dbutil (); $result = $util->query ($sql); while ($row = $result->fetch_assoc ()) {echo "$row [Stuname]". </br> "; } $result->free (); $util->close ();*/ $sql= "Update m_student set stuname= ' Yang mi ' where id=3"; $util=NewDbutil (); $result=$util->otheroperate ($sql); Echo $result; $util-close ();?>
Reference reading: www.manongjc.com/article/1206.html
PHP using mysqli Extension Library to implement additions and deletions (object-oriented version)