[nycphp-talk] Writing Database Agnostic Code
Kenneth Downs
ken at secdat.com
Wed Feb 14 16:14:19 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...
There are two levels of this.
At the first level, you to do basic SQL passthrough without worrying
about whether to use pg_fetch_array() or mysql_fetch_array().
At the second level you need to hide the fact that some SQL variants
want to say "SELECT * FIRST 10 FROM .... " while others insist on
"SELECT * FROM... ORDER BY x limit 5". The usual solution here is to
create replacement functions that build your SELECT statements for you.
>
> 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?
> ------------------------------------------------------------------------
>
> _______________________________________________
> New York PHP Community Talk Mailing List
> http://lists.nyphp.org/mailman/listinfo/talk
>
> NYPHPCon 2006 Presentations Online
> http://www.nyphpcon.com
>
> Show Your Participation in New York PHP
> http://www.nyphp.org/show_participation.php
-------------- next part --------------
A non-text attachment was scrubbed...
Name: ken.vcf
Type: text/x-vcard
Size: 261 bytes
Desc: not available
URL: <http://lists.nyphp.org/pipermail/talk/attachments/20070214/ec0f2054/attachment.vcf>
More information about the talk
mailing list