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, 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 names'utf8';
Author:volcano