Home  >  Article  >  Backend Development  >  php--PDO introduction and installation configuration

php--PDO introduction and installation configuration

伊谢尔伦
伊谢尔伦Original
2016-11-22 09:38:471292browse

Introduction

The PHP Data Objects (PDO) extension defines a lightweight, consistent interface for PHP to access databases. Each database driver that implements the PDO interface can expose database-specific features as standard extensions. Note that using PDO extensions by itself does not implement any database functionality; a database-specific PDO driver must be used to access database services.

PDO provides a data access abstraction layer, which means that no matter which database is used, the same functions (methods) can be used to query and obtain data. PDO does not provide a database abstraction layer; it does not rewrite SQL and does not emulate missing features. If necessary, a mature abstraction layer should be used.

PDO has been included since PHP 5.1, and is used as a PECL extension in PHP 5.0. PDO requires new features of PHP 5 core and therefore will not run on older versions of PHP.

Installation Configuration

Installing PDO on Unix systems


Since PHP 5.1.0, PDO and PDO_SQLITE drivers are available by default. For the database of your choice, you need to enable the corresponding POD driver;

Note:

When building PDO with shared extensions (not recommended), all PDO drivers must be loaded after PDO itself.

When installing PDO as a shared module, you need to update the php.ini file so that the PDO extension is automatically loaded when PHP is run. Specific database drivers also need to be enabled there; make sure they are listed after the pdo.so line, as PDO must be initialized before the specific database extensions can be loaded. If you are building PDO and database-specific extensions statically, you can skip this step.

extension=pdo.so

Windows environment


PDO and all major drivers are distributed with PHP as shared extensions, to activate them simply edit the php.ini file:

extension=php_pdo.dll

Note:

This step is available in PHP 5.3 and above Not required in later versions, for PDO no longer needs to be a DLL file.

Next step, select other database-specific DLL files, and then either load them with dl() at runtime, or enable them behind php_pdo.dll in php.ini. For example:

extension=php_pdo.dll
extension=php_pdo_firebird.dll
extension=php_pdo_informix.dll
extension=php_pdo_mssql.dll
extension=php_pdo_mysql.dll
extension=php_pdo_oci.dll
extension=php_pdo_oci8.dll
extension=php_pdo_odbc.dll
extension=php_pdo_pgsql.dll
extension=php_pdo_sqlite.dll

Those DLL files should exist in the system’s extension_dir.

Note:

Remember: After changing the php.ini file, you need to restart the PHP service for the new configuration instructions to take effect.


Statement:
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