Home  >  Article  >  Backend Development  >  Some predefined constants of PDO_MYSQL_PHP tutorial

Some predefined constants of PDO_MYSQL_PHP tutorial

WBOY
WBOYOriginal
2016-07-13 17:36:33764browse

PDO_MYSQL is a mysql extension of the PHP Data Objects (PDO) interface. Take a closer look at the PHP manual. In fact, there are still some interesting parameters available for use, such as:

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 QUERY. The most common use case 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 namesutf8;
Author: volcano

www.bkjia.comtruehttp: //www.bkjia.com/PHPjc/486633.htmlTechArticlePDO_MYSQL is a mysql extension of the PHP Data Objects (PDO) interface. Take a closer look at the PHP manual. In fact, there are still some interesting parameters available for use, such as: PDO::MYSQL_ATTR_INIT_COMM...
Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn