about how PHP implements the Mysqli extension Library (object-oriented), adding and deleting instances to share

Source: Internet
Author: User
This article mainly introduces the implementation of PHP based on object-oriented Mysqli expansion library additions and deletions of the Operation tool class, combined with the case analysis of mysqli additions and deletions to the Operation class packaging and use skills, the need for friends can refer to the next

This paper describes the PHP implementation based on object-oriented Mysqli expansion library additions and deletions to the Operation tool class. Share to everyone for your reference, as follows:

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 Extension Library Operations Database tool class


<?php//Database operation class dbutil{  private $host = "localhost";  Private $username = "root";  Private $password = "123456";  Private $dbname = "student";  private $conn;  Public Function Dbutil () {   $this->conn=new mysqli ($this->host, $this->username, $this->password,$ This->dbname) or Die ($this->conn->connect_error);  } Query public  function query ($sql) {   $all = $this->conn->query ($sql);   return $all;  } Insert, modify, delete public  function Otheroperate ($sql) {   if ($this->conn->query ($sql)) {    if ($this- conn->affected_rows>0) {      return "OK";    } else{      return "Erroor";}}  }  Public function Close () {   $this->conn->close ();  }}? >

2. The following is the code that invokes the tool class


<?php require_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 =new dbutil ();  $result = $util->otheroperate ($sql);  echo $result; $util->close ();? 

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.