This time to everyone to bring PDO to MySQL database additions and deletions to change the operation of the steps in detail, PDO on the MySQL database additions and deletions to the attention of the operation of the matter, the following is the actual case, a look.
Objective
PDO one is the abbreviation for PHP data Object (PHP.
You cannot perform any database operations using the PDO extension itself, you must use a database-specific PDO driver (PDO driver for a specific database) to access the database server.
PDO does not provide a database abstraction, it does not rewrite SQL or provide functionality that is missing from the database itself, and if you need this functionality, you need to use a more mature abstraction layer.
Recently in the project to use the PDO operation MySQL database, so I wrote a class file, named mysql_class.php file code as follows:
Sample code
<?phpclass mysql{//constant Declaration const DSN = "mysql:host=[database address];d bname=[database name];charset=utf8";//Database address and database name and code const USERNAME = "[Database user name]";//user name Const PASSWD = "[Database password]";//password//private variable declaration Private $sql = Null;//sql statement cache private $link = null;//database connection Priva Te $result = null;//result/******************************************************************************* * @ name: Establish connection * @ Property: *******************************************************************************/Private Function connect () { try {$this->link = new \pdo (self::D sn, self::username, self::P asswd, array (Pdo::attr_errmode = Pdo::errmode_exce ption));//Create Connection} catch (Pdoexception $e) {die ("error!:". $e->getmessage (). "
Believe that you have read the case of this article you have mastered the method, more exciting please pay attention to the PHP Chinese network other related articles!
Recommended reading:
PHP namespace usage in a detailed
Laravel 5.5 Core Architecture usage