NYCPHP Meetup

NYPHP.org

[nycphp-talk] Writing Database Agnostic Code

David Krings ramons at gmx.net
Wed Feb 14 12:07:22 EST 2007


Brian Dailey wrote:
> A lot of the books and other material that I've been reading talk about 
> database abstraction - developing your application so that you can use 
> different database backends without significant (or maybe any) changes 
> to your code. Pear::DB seems to really do a good job with this. However...
> 
> In the past, I've always used MySQL or Oracle, but mostly MySQL. Each 
> SQL distribution has its own peculiar ways of doing some things, and I 
> know that using some of the MySQL functions makes the code far easier to 
> write and also optimizes the speed of the query.
> 
> So my question boils down to this: how does one balance writing code 
> that works regardless of the backend and still keep things optimized for 
> speed and clarity? Are there any generalized tips that any of you can 
> share from your experiences?
> 

I thought about doing that for one of my small projects, but then 
decided to make it blatantly ignorant to anything non-MySQL. My app 
doesn't talk to anything else other than its own tables and the expected 
  db traffic is easily handled with an off-the-shelf MySQL configuration.

The question to ask is if there is any circumstance where it is likely 
that any other db backend is used other than the one of choice?
It also depends on how complicated the db access is. Getting some simple 
inserts, updates, and selects to work for several db backends is 
probably much easier than the real difficult stuff.

David



More information about the talk mailing list