The full version of the mysql operation class implemented by PHP has been used, and this simplified version is a simplified version after the full version is modified. It is applicable to common PHP applications, you can add, delete, modify, and query operations.
The full version of the mysql operation class implemented by PHP has been used, and this simplified version is a simplified version after the full version is modified. It is applicable to common PHP applications, you can add, delete, modify, and query operations.
The simple Mysql operation class encapsulated by myself has been written in the Ben framework based on PDO, and the code style has no headers...
Mysql. class. php
<? Phpclass mysql extends PDO {public $ server; public $ database; public $ user; public $ password; public $ SQL; public function _ construct ($ server, $ database, $ user, $ password, $ port = 3306) {$ this-> server = $ server; $ this-> database = $ database; $ this-> user = $ user; $ this-> password = $ password; parent ::__ construct ("mysql: host = $ server; port = $ port; dbname = $ database", $ user, $ password); $ this-> query ('set NAMES utf8');} public function drop ($ table) {$ SQL = 'drop Table '. $ table. '; $ re = $ this-> query ($ SQL); if ($ re) {return true;} else {return false ;}} public function insert ($ table, $ name, $ value = null) {$ SQL = "INSERT ". $ table. '('; if ($ value = null) {$ arrname = array_keys ($ name); $ arrvalue = array_values ($ name );} else {$ arrname = explode ('|', $ name); $ arrvalue = explode ('|', $ value) ;}for ($ I = 0; $ I Query ($ SQL); if ($ re) {return true;} else {return false;} public function delete ($ table, $ Conditionsname, $ Conditionsvalue = null) {if ($ Conditionsvalue! = Null) {$ SQL = "DELETE FROM ". $ table. "WHERE ". $ Conditionsname. "= '". $ Conditionsvalue. "';";} else {$ SQL = "DELETE FROM ". $ table. "WHERE"; $ arrname = array_keys ($ Conditionsname); $ arrvalue = array_values ($ Conditionsname); for ($ I = 0; $ I Query ($ SQL); if ($ re) {return true;} else {return false;} public function select ($ table, $ name, $ Conditionsname, $ Conditionsvalue = null) {if ($ Conditionsvalue! = Null) {$ SQL = "SELECT ". $ name. "FROM ". $ table. "WHERE ". $ Conditionsname. "= '". $ Conditionsvalue. "';";} else {$ SQL = "SELECT ". $ name. "FROM ". $ table. "WHERE"; $ arrname = array_keys ($ Conditionsname); $ arrvalue = array_values ($ Conditionsname); for ($ I = 0; $ I Query ($ SQL); $ row = $ re-> fetch (); return $ row [$ name];} public function update ($ table, $ name, $ value, $ Conditionsname, $ Conditionsvalue = null) {if ($ Conditionsvalue! = Null) {$ SQL = "UPDATE ". $ table. "SET ". $ name. "= '". $ value. "'where ". $ Conditionsname. "= '". $ Conditionsvalue. "';";} else {$ SQL = "UPDATE ". $ table. "SET ". $ name. "= '". $ value. "'where"; $ arrname = array_keys ($ Conditionsname); $ arrvalue = array_values ($ Conditionsname); for ($ I = 0; $ I Query ($ SQL); if ($ re) {return true;} else {return false;} public function group ($ table, $ name) {$ SQL = "SELECT ". $ name. "FROM ". $ table. ";"; $ return = array (); $ re = $ this-> query ($ SQL); while ($ row = $ re-> fetch (PDO :: FETCH_ASSOC) {array_push ($ return, $ row [$ name]);} return $ return;} public function fetchall ($ SQL) {$ return = array (); $ re = $ this-> query ($ SQL); while ($ row = $ re-> fetch (PDO: FETCH_ASSOC) {array_push ($ return, $ row) ;}return $ return ;}}