Home > 类库下载 > PHP类库 > body text

PHP uses the mysqli extension library to implement addition, deletion, modification and query (object-oriented version)

高洛峰
Release: 2019-02-23 15:07:46
Original
1319 people have browsed it

The mysqli extension library is an improved version of the mysql extension library. It improves stability and efficiency on the basis of the mysql extension library. The mysqli extension library has two sets of things, one is process-oriented mysqli and the other is object-oriented. mysqli. The operation method is generally the same as that of the mysql extension library. This time, we first extract a tool class for operating mysql and the calling class.

Recommended related mysql video tutorials: "mysql tutorial"

1. mysqli extension library operation database tool class

conn=new mysqli($this->host, $this->username, $this->password,$this->dbname) or die($this->conn->connect_error);
    
   }
  //查询
   public function query($sql){
     $all= $this->conn->query($sql);
     return $all;
   }
  //插入,修改,删除
   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();
   }
  }
?>
Copy after login

2. The following is the specific code for calling the tool class

query($sql);
   while($row=$result->fetch_assoc()){
        echo "$row[stuName]"."";
   }
   $result->free();
   $util->close();*/
   $sql="update m_student set stuName='杨幂' where id=3";
   $util=new DBUtil();
   $result=$util->otherOperate($sql);
   echo $result;
   $util->close();
?>
Copy after login

source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Recommendations
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template