classsqlhelper{Private $conn; Private $host= ' localhost '; Private $user= ' Root '; Private $pwd= ' Root '; Private $db; Public function__construct ($idb) {$this->db =$idb; $this->conn =NewMysqli ($this->host,$this->user,$this-$this->pwd,$this-IDB); if($this->conn->connect_error) {$this->error ($this->conn->connect_error); }$this->conn->query (' Set names UTF8 '); } //for SELECT statements Public functionEXECUTE_DQL ($sql){ $res=$this->conn->query ($sql) or$this->error (' query operation failed '.$this->conn->error); $this-Free (); return $res; }//for INSERT, UPDATE, Delect Public functionEXECUTE_DML ($sql){ $flag=$this->conn->query ($sql) or$this->error ($this->conn->error); if(!$flag) {return0;//operation failed}Else{if($this->conn->afffected_rows > 0) {return1;//Operation succeeded}Else{return2;//operation failed with no number of rows affected }}}//for multi-line records Public functionFetch_all ($sql) {$res=$this->conn->query ($sql) or$this->error (' query operation failed '.$this->conn->error); $arr=Array(); while($row=$res-Fetch_assoc ()) {$arr[] =$row;//release resources in a timely manner}return $arr;}protected functionError$err){ $log= ' Cur.log '; File_put_contens ($log,$err,file_append); die($err);}}
php-based on object-oriented MySQL class