#native_company# #native_desc#
#native_cta#

A Practical Approach to Object-Relational Mapping in PHP

By PHP Builder Staff
on March 8, 2004

by Kieran Mathieson
PHP applications use various technologies, like HTML, relational databases (RDB), JavaScript,
object-oriented programming (OOP), and so on. Most of them work well together. For instance,
PHP code can easily write JavaScript, JavaScript can use a browser’s document object model
(DOM) to change HTML, etc.
OOP and RDB don’t fit together quite as well. When programmers write code mapping PHP classes to
RDB tables, they need to make sure the classes do not become too dependent on each other. Otherwise,
changes in one class will require changes in others, raising development and maintenance costs.
If software changes become too expensive and take too much time, applications will restrict business
innovation, rather than enabling it.
This paper offers a practical solution to the object-relational problem in PHP. “Practical” means
an approach meeting the constraints that usually apply in application development:
  • Limited cash.
  • Limited time.
  • Limited expertise.
  • Shared or inexpensive dedicated servers not under developers’ full control.
  • Basic tools like PHP and MySQL.
  • Sharing data between the application and other tools, like Access and Excel.
  • Handling authentication, permissions, transaction logging, error control,
    multi-user updates, and so on.
We’ll use the term “application utility tasks” to refer to the things listed in the last bullet point.
They often consume significant resources, sometimes more than the rest of the application. Carefully
managing application utility tasks is important to application stability and performance. It’s usually
best to start building them in at the very beginning of a project, rather than try to add them later.
This paper assumes you’re familiar with PHP, OOP, and relational databases. If you’re not, you might
want to consult these tutorials:

1
|
2
|
3
|
4
|
5
|
6
|
7
|
8
|
9
|