At this stage PHP to operate MySQL database PHP to provide us with 3 sets of libraries
1. mysql extension library for process operation
2. Mysqli expansion Library object-oriented operation and process-oriented operation coexist security and efficiency higher than MySQL extension library
3. PDO expansion Library object-oriented operation
Today this post is mainly about MySQL extension library and mysqli expansion library is mainly recorded 2 sets of crud operation of the sub-assembly
The following code snippet is about the encapsulation of the Mysqli extension library about CRUD operations
Header ("Content-type:text/html;charset=utf-8"), class Sqlitool{private $mysqli;p rivate static $host = "localhost"; private static $user = "root";p rivate static $pwd =123456;private static $db = "Test";p ublic function __construct () {$this- >mysqli=new mysqli (self:: $host, Self:: $user, Self:: $pwd, Self:: $DB); if ($this->mysqli->connect_error) {die ( "Link failed". $this->mysqli->connect_error);} Sets the character set $this->mysqli->query ("Set names UTF8") that accesses the database; Public Function Execute_dql ($sql) {$res = $this->mysqli->query ($sql) or Die ("Operation failed". $this->mysqli->error); return $res;} Public Function Execute_dml ($sql) {$res = $this->mysqli->query ($sql) or Die ("Operation failed". $this->mysqli->error); if (! $res) {return 0; Operation failed}else{if ($this->mysqli->affected_rows>0) {return 1;//indicates success}else{return 2;//indicates no row received effect}}}}
The following code snippet is about the package for the MySQL extension library about CRUD operations
Header ("Content-type:text/html;charset=utf-8");
Class Sqltool{private $con;p rivate $host = "localhost";p rivate $user = "root";p rivate $password =123456;private $db = "Test ";//constructor Initialize database operation link and set character Set function Sqltool () {$this->con=mysql_connect ($this->host, $this->user, $this- password); if (! $this->con) {die ("link Database error". Mysql_error ());} mysql_select_db ($this->db, $this->con); mysql_query ("Set names UTF8");} Complete the Query task Yes Public Function EXEUTE_DQL ($sql) {$res =mysql_query ($sql) or Die (Mysql_error ()); return $res;} Represents the Insert Update Deletepublic function exeuct_dml ($sql) {$b =mysql_query ($sql, $this->con) or Die (Mysql_error ()); (! $b) {return 0;//failed}else{if (mysql_affected_rows ($this->con) >0) {return 1;//indicates success}else{return 2;//indicates no row count affected}}}
}
"Summary" CRUD operations encapsulation for MySQL extension library and mysqli extension library