"Elaborate PHP" sample chapter fourth edition Chapter 18 database abstraction layer PDO 2

18.2 PDO supported database

Use PHP can handle a variety of database systems, including MySQL, PostgreSQL, Oracle, MsSQL and so on. However, when accessing different database systems, PHP extension functions they use are different. For example, use PHP's MySQL or MySQLi extension function, can only access the MySQL database; If you need to handle Oracle database, you must install and re-learning process in Oracle PHP extension libraries, each database has a corresponding extension function, as As shown in 18-3. All need to learn each database application-specific libraries, this is more trouble, more importantly, it makes difficult to achieve portability across databases.

To solve this problem, we need a 'database abstraction layer. " It can solve the coupling between the application logic and database communication logic, through the common transfer all of the database command interface, an application can use a database of a variety of solutions, as long as the support database application desired characteristics, but also provides a level of abstraction compatible with the driver database. Figure 18-4 mode application database abstraction layer.

PDO is a "database access abstraction layer" whose role is a unified interface to access various databases, can easily switch between the different databases, so that migration between databases easily achieved. Compared with the MySQL and MySQLi library, PDO allow the use of cross-database more user-friendly; ADODB and compared with other similar MDB2 database access abstraction layer, PDO is more efficient. In addition, all PDO database extensions supported by PHP are very similar, because PDO draws on the best characteristics of the previous database extensions.

83cb68c1e77a4e0384f96b41e79ee753.png

FIG. 18-3 each database has a corresponding extension function

 

93e2ffe87f09448a864f63b54816403b.png

Figure 18-4 Application mode database abstraction layer

 

The operation of any database, using the PDO extension itself is not executed, you must use a specific PDO drivers for the different database server access. PDO extension and the driver was a local RDBMS client API libraries to build bridges, to access the specified database system. This can greatly increase the flexibility of the PDO, PDO load the database because the necessary drivers at runtime, there is no need to re-configure and compile PHP every time you use a different database. For example, if the database server needs to switch from MySQL to Oracle, as long as reload PDO_OCI driver on it. PDO-supported database and corresponding drive shown in Table 18-1.

 

Table 18-1 PDO-supported database drivers and corresponding

 

792fcd076a7b4644a7fb085bdac024d0.png

   

 

PDO want to determine whether a driver is available in the environment, () function, the view in the browser list by loading phpinfo PDO portion, or view pdo_drivers () function returns the array to determine.

 

 

9a94902939524c6a8fb46e1b6ae3b493.png

Guess you like

Origin www.cnblogs.com/itxdl/p/11375161.html