magazine resources subscribe about advertising

New Architect Daily
Commentary and updates on current events and technologies

CMP Media E-Book

Download your copy today.

Research
Search for reports and white papers from industry vendors and analysts.

This Week at NewArchitect.com Subscribe now to our free email newsletter and get notified when the site is updated with new articles







Day of Defeat Online Gaming

 New Architect > Archives > 2000 > 10 > Programming Feature  

A Database-Independent API for PHP

By Sterling Hughes

PHP is a valuable item in any Web developer's toolbox. The server-side technology allows for rapid development of dynamic, database-driven applications. One of PHP's major strengths is its ability to connect with many different databases, including Sybase, PostgreSQL, Oracle, or MySQL.

Database connectivity, however, is also one of PHP's major weaknesses. Specifically, PHP's lack of a standard database API makes switching databases difficult and costly once an application has been written. For example, if you write a program that uses a MySQL database on the back end, and you want to modify that program so that it uses a Sybase database, you'll most likely spend hours modifying the code.

Highest Form of Flattery

Fortunately, there are several workarounds to this problem, including a couple that rely on new features in PHP4. A lot can be learned from examining (and borrowing) a solution from Perl. For the particular solution presented here, I've used Perl's DBI as a model. Before Perl 5, many Perl programmers faced the same problem that PHP programmers face today. They had to use different modules and subroutines to access different databases. For example, the sybperl module worked with Sybase, while oraperl interfaced with Oracle. Switching databases meant going through the code and changing all references from sybperl to oraperl. Perl programmers got frustrated and began looking for a better solution. The result was the DBI module.

DBI lets you access many different databases with the same set of methods.




  Day of Defeat Online Gaming

home | daily | current issue | archives | features | critical decisions | case studies | expert opinion | reviews | access | industry events | newsletter | research | careers | info centers | advertising | subscribe | subscriber service | editorial calendar | press | contacts


Copyright © 2006 CMP Media, LLC Read our privacy policy, your California privacy rights, terms of service.
SDMG Web sites: BYTE.com, C/C++ Users Journal, Developer Pipeline, Dr. Dobb's Journal, DotNetJunkies, MSDN Magazine, Sys Admin,
SD Expo, SD Magazine, SqlJunkies, The Perl Journal, Unixreview, Windows Developer Network, New Architect

web2