CHAPTER 6 – PEAR DB – Pros and Cons of Database Abstraction

The two main advantages of using a database abstraction layer such as PEAR DB are A single API is easy to remember. You are more productive when you spend less time looking up the documentation. A single API allows other components to use the DB API for generic DBMS access, without worrying about back-end specifics. Because DB is implemented in PHP, these advantages come at a cost: A layer written in PHP is slower than using built-in PHP functions, espe- cially if running without an opcode cache. The extra layer of code adds complexity and potential error sources. Deciding the right choice for you depends on your needs. Requirements that speak for using PEAR DB or another form of abstracted DBMS access are portability, reusability, rapid development, or that you already use other PEAR packages. Some requirements that speak against using PEAR DB are high perfor- mance requirements where the database itself would not be the bottleneck, a significant buy-in with some specific DBMS product, or a policy of avoiding external dependencies.

6.4.3 Which Features Are Abstracted? DB does not abstract everything, such as SQL or database schema grammar. The features it does abstract are Database connections Fetching results Binding input variables (prepare/execute) Error reporting Sequences Simple database and table descriptions Minor quirks and differences The following are not abstracted, either because they are outside the scope of DB, too expensive, or simply not yet implemented: SQL syntax Database schemas (CREATE TABLE, for example) Field types Character encodings Privilege management (GRANT, and so on) Database schemas and field types are abstracted by the MDB package, which is another database abstraction layer found in PEAR. MDB is a merge of Metabase and DB, two of the most popular database abstraction layers for PHP. The intent behind MDB has been to merge with the next major DB release.

Post Comment
Login to post comments