<?php/*//pdo Connection Information $pdo=array ("Mysql:host=localhost;dbname=demo;charset=utf8", "Root", "");//Start connecting to database $db = MySQL:: Newclass (); $db->pdoconnect ($pdo); $updateRow = Array ("user_id" = "2", "meta_key" = "username");//$db Select ("Wp_usermeta"); Send sql//$result = $db->selectone (); Get a piece of data//$DB->selectcount (); Get all//$db->update ("Wp_usermeta", $updateRow, "umeta_id=1"); Update information//$DB->insert ("Wp_usermeta", $updateRow); Insert Data//echo $db->lastinsertid (); Get the inserted id//$db->delete ("Wp_usermeta", "umeta_id>18"); Delete data */class mysql{private static $object; Private $PDO; Private $prepare; Singleton mode start Private function __construct () {} public static function Newclass () {if (! Self:: $object instanceof Self)} {self:: $object = new Self; } return Self:: $object; } public Function __clone () {Trigger_error (' clone was not allow! ', e_user_error); }//////Singleton mode end//Connect PDO public Function Pdoconnect ($address) {try{$this->pdo = new PDO ($address [0], $address [1], $address [2]); $this->pdo->setattribute (pdo::attr_persistent,true); Set throw error $this->pdo->setattribute (pdo::attr_errmode,pdo::errmode_exception); Sets the null $this->pdo->setattribute (pdo::attr_oracle_nulls,true) that is converted to SQL when the string is empty; The escaped processing of the variable by MySQL $this->pdo->setattribute (pdo::attr_emulate_prepares, false); }catch (pdoexception $e) {$this->msg ("PDO connection Error message:". $e->getmessage ()); }}//Error alert Private Function MSG ($the _error= "") {$html = "
PHP PDO Operation class