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