Wednesday, July 04, 2007

Developing PHP multi database applications.

When developing a website or web enabled solution in PHP most developers do consider the fact that there database might be migrated to a newer version, what most do not consider is that they have to migrate to a completely different database platform. This might sound strange to some as they are developing there application for a specific database platform. However, when you develop a application which can be used at several sites you might not always be able to rely on the same database. Or in cases you are building a opensource or commercial solution you users might not always want to work with the database you have in mind. You might be developing your code on a Oracle 10G database while your customer thinks a Oracle database is overkill and wants to use a MySQL or PostgreSQL database.

For those who are not familiar with the three tier architecture, this architecture is describing the situation where you have a client, application server and a infrastructure server. The client is in a PHP web enabled solution a customer running a web browser, the application server is running a webserver with the PHP engine enabled. The infrastructure server is running a database. In the picture below you will see that all tiers are represented by a different server (or client pc). What you normally will see in not so critical environments is that the applications server and the database server are running on the same hardware platform.

When planning to build a PHP solution you might want to think about this problem and might plan in advance. To prevent that you need to write code for every possible database platform you will need to have a SQL translating engine in the middle. Even SQL is quite a standard language there are quite some differences between the database vendors SQL implementation.

You might consider to write your own SQL translator however there is a good opensource solution which can help you with this problem. ADOdb is a database abstraction library for PHP and will give you support on MySQL, PostgreSQL, Interbase, Firebird, Informix, Oracle, MS SQL, Foxpro, Access, ADO, Sybase, FrontBase, DB2, SAP DB, SQLite, Netezza, LDAP, and generic ODBC, ODBTP. This enables you to write a single code pack to connect to all those “infrastructure” tiers instead of writing code for all those platforms.

Using the solution as shown above will prevent you from having the situation as shown here that you have to develop and maintain a large number of releases. Even do your developers will have to learn to adopt a new way of coding it will in the long run pay of when you decide to migrate to a different database platform or when you are working on a solution you will be distributing to customers. When you are developing

No comments: