Introduction to PDO at the php database abstraction layer and simple examples

Source: Internet
Author: User
& Amp; nbsp; what is the database abstraction layer? You only need to understand the role of the database abstraction layer. the database abstraction layer can be easily transferred when you switch from one database to another without modifying too much code. Use the database abstraction layer to simplify the code

 

What is the database abstraction layer? You only need to understand the role of the database abstraction layer. the database abstraction layer can be easily transferred when you switch from one database to another without modifying too much code. With the database abstraction layer, the code is more standardized and the efficiency is greatly improved! Common Database abstraction layers include ADODB, PHPLi, and PDO. today we will talk about the application of PDO!

The benefits of PDO are Needless to say. compared with mysql and mysqli function libraries, PDO makes cross-database usage more friendly; compared with ADODB, PDO is more efficient.

I believe everyone will use php5.0 and later versions. Congratulations! the php package already comes with PDO. But you still need to open the extension in php. ini!

Extension = php_pdo.dll

Extension = php_pdo_mysql.dll

Extension = php_pdo_pgsql.dll

Extension = php_pdo_sqlite.dll

Extension = php_pdo_mssql.dll

Extension = php_pdo_odbc.dll

Extension = php_pdo_firebird.dll

Extension = php_pdo_oci8.dll

The above extensions correspond to different Database Drivers. which Database do you use? just remove the previous extensions. I use mysql.

PDO connection database:

The php Tutorial is as follows:


 True); // use try .. catch check connection successful try {foreach ($ db-> query ('select * from user') as $ row) {print_r ($ row) ;}$ db = null; // Close the database} catch (PDOException $ e) {echo $ e-> getMessage () ;}?>

The above php code uses common queries and can be queried in other ways!

In the next article, we will introduce in detail various usage methods of PDO!

 

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.