Home > Backend Development > PHP Tutorial > Some predefined constants of PDO_MYSQL_PHP tutorial

Some predefined constants of PDO_MYSQL_PHP tutorial

WBOY
Release: 2016-07-13 17:36:33
Original
789 people have browsed it

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...
Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template