Detailed description of using PDO constructor to connect to database and DSN

Source: Internet
Author: User
Pdo is a newly added database abstraction layer in php5. to solve the problem of accessing the unified interfaces of different databases. Similar to PEAR: DB Class and ADODB class operations, but it is directly encapsulated in php extension and can be freely used. Detailed description of using PDO constructor to connect to database and DSN

Pdo is a newly added database abstraction layer in php5. to solve the problem of accessing the unified interfaces of different databases. Similar to PEAR: DB Class and ADODB class operations, but it is directly encapsulated in php extension and can be freely used.

In the previous article, what is PDO? In the overview of PDO and the method for installing PDO, we will introduce what PDO is, the features and installation of PDO, in this article, we will introduce the details of connecting the PDO constructor to the database and DSN!

PDO constructor connects to database

In PDO, to establish a database connection, you need to instantiate the PDO constructor. the syntax format of the PDO constructor is as follows:

_construct(string $dsn[,string $username[,string $password[,array $driver_options]]])

The constructor parameters are described as follows:

Dsn: data source name, including the host name, port number, and database name.

Username: The username used to connect to the database.

Password: password used to connect to the database.

Driver_options: other options for connecting to the database.

The following describes how to connect to the MySQL database through PDO. the specific code is as follows:

 GetMessage ()."
";}

The output result of the page is as follows:

We will introduce how to use the PDO constructor to connect to the database and DSN here. you can test it locally. here we will introduce several methods for executing SQL statements in PDO, for more information, see "three methods for executing SQL statements in PDO".

The above is the detailed description of connecting to the database and DSN using the PDO constructor. For more information, see other related articles in the first PHP community!

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.