One of our obsessions is to generate the cleanest objects possible so that they're easy to understand and use. To achieve this, we need to make sure the same code is not unnecessarily repeated across objects. Therefore, PHP Object generator abstracts common database-related code into a separate database class (class.database.php) which is also provided to you upon code generation. We call this database class the POG database wrapper.
There is another wrapper that you can choose if you're generating code for PHP 5.1 & above: PDO. PDO is the new lightweight and consistent database interface for PHP and is one of the new features included in the PHP distribution as of version 5.1. Unlike the POG wrapper or any other external abstraction layer such as PEAR DB, PDO is part of the PHP core, which means that PDO functions can be called just like any other PHP functions without the need to include any external files. PHP Object Generator can generate objects compatible with PDO and in fact, PDO is the default wrapper selected by POG whenever a user chooses to generate code for PHP 5.1 & above.
Which wrapper should you choose?
|PHP Version||We recommend choosing:|
|5.1 & above||PDO|
|5.0 & below||POG (no other choice)|
What is a database wrapper?
In programming, a wrapper is a component which changes the interface of an existing component, in order to increase its compatibility with various other systems.
Because there are many types of databases, each with their own interface, a popular technique used in database programming is to create a wrapper which offers a common interface for database interaction. As an analogy, you can think of a database wrapper as an "interpreter" who knows all the different languages spoken by the different databases. So you can communicate to the "interpreter" in your own language, and it will take care of translating your request, obtain your result and translate it back in a language that you understand.
Why do generated objects need a database wrapper?
As described in the Introduction to POG, POG generates objects which use the Object Relational Mapping, or ORM, programming pattern where "objects" are used to represent rows in a database table. Each object also comes with 5 integrated CRUD methods which allow you to perform atomic database operations.
Instead of repeating the code that performs those database operations across objects, we've abstracted, or grouped them, in a separate database class. This Database class (class.database.php) is required by your object so that it can perform database operations such as "Save", "Delete", "Get" etc. It's also important to note that currently, this database wrapper is specific to MySQL only and won't work if you're planning to use other databases, such as Oracle.
More about PDO
From the PHP website
The PHP Data Objects (PDO) extension defines a lightweight, consistent interface for accessing databases in PHP. Each database driver that implements the PDO interface can expose database-specific features as regular extension functions. Note that you cannot perform any database functions using the PDO extension by itself; you must use a database-specific PDO driver to access a database server.
PDO provides a data-access abstraction layer, which means that, regardless of which database you're using, you use the same functions to issue queries and fetch data. PDO does not provide a database abstraction; it doesn't rewrite SQL or emulate missing features. You should use a full-blown abstraction layer if you need that facility.
PDO ships with PHP 5.1, and is available as a PECL extension for PHP 5.0; PDO requires the new OO features in the core of PHP 5, and so will not run with earlier versions of PHP.