php--PDO introduction and installation configuration

伊谢尔伦
Release: 2016-11-22 09:38:47
Original
1334 people have browsed it

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
Copy after login

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
Copy after login

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
Copy after login

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.


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