Home >Backend Development >PHP Tutorial >Some predefined constants of PDO_MYSQL_PHP tutorial
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) 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 PLAIN TEXT
Command to execute when connecting to the MySQL server. Will automatically be re-executed when reconnecting.
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:
CODE:
set namesutf8;
Author: volcano