Use the new object-oriented features of PHP 5 to create classes that wrap access to any database table.
PHP 5 represents a substantial upgrade in terms of object-oriented support in the PHP language. Along with a number of upgrades in performance, PHP 5 has a major upgrade in the ability to create dynamic classes. These are classes where the methods and attributes change from object to object. This can be very handy in building database applications.
Usually, there is one PHP class for each table in the database.
For example, if you have tables named books, authors, and publishers,
you would have PHP classes named
PHP class has methods to get and set the values in a record in the
On the one hand, this is a very clean and easy-to-understand
model. On the other hand, it's a lot of work to maintain these classes
(and that's just for three tables!). Is it possible to write a single
class that will wrap any table in the database? Yes. With PHP 5's
_ _call, _ _get, and
_ _set methods, it is.
To understand why
_ _call, _
_ _set are important you need to understand how methods on objects get called. When you invoke a method on an object, the interpreter first looks at the class to see whether the method exists. If the method does exist, it's called; if it doesn't, the base class of the class is inspected; if that fails, the base class of the base class is examined, ...