Home  >  Article  >  类库下载  >  PHP uses the mysqli extension library to implement addition, deletion, modification and query (object-oriented version)

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

高洛峰
高洛峰Original
2016-10-09 11:32:521316browse

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();
   }
  }
?>

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();
?>

Statement:
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
Previous article:PHP essenceNext article:PHP essence

Related articles

See more