Some predefined constants of PDO_MYSQL

Source: Internet
Author: User
Some predefined constants of PDO_MYSQL. read some predefined constants of PDO_MYSQL. PDO_MYSQL is a mysql extension of PHPDataObjects (PDO) interface. Take a closer look at the php Manual. In fact, some interesting parameters are available, such as PDO: MYSQL_ATTR_INIT_COMMAND (integer)

PDO_MYSQL is a mysql extension of the PHP Data Objects (PDO) interface. Taking a closer look at the php manual, there are still some interesting parameters available, for example:

PDO: MYSQL_ATTR_INIT_COMMAND (integer)
Command to execute when connecting to the MySQL server. Will automatically be re-executed when reconnecting.

When I use PDO_MYSQL to connect to mysql, I can use this parameter to automatically execute some queries. The most common application scenario is to connect to mysql using the UTF-8 character set:

PLAIN TEXT
CODE:
$ Db = new PDO ("mysql: dbname = dbname", "user", "password", array (PDO: MYSQL_ATTR_INIT_COMMAND => "set names 'utf8 '"));
The above code will execute SQL immediately after connecting to mysql:

PLAIN TEXT
CODE:
Set names 'utf8 ';
Author: volcano

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.