PDO to MySQL database additions and deletions to change the operation of the steps detailed

Source: Internet
Author: User
Tags openid
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

Related Article

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.