Simple Mysql operations using php

Source: Internet
Author: User
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 ;}}

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.