You are here: Re: Abstracting a database class « PHP Programming Language « IT news, forums, messages
Re: Abstracting a database class

Posted by David Haynes on 01/01/06 03:18

Full Decent wrote:
> Hey all!
>
> I've been using PHP for a while and I'm hearing that I should look into
> using it OO. I'm looking into making changes to the program Camera Life
> (http://fdcl.sf.net). I want to abstract the connection to the database
> which is currently MYSQL and maybe implement another database, or just
> leave it open for addition. If I get lucky and get the hang of this,
> I'd also like to abstract calls to GD.
>
> So firstly, is there a good solution to this problem? I've seen many
> examples, but many of them are incomplete or simply academic. Also,
> will I lose any functionality by doing it this way? I am currently
> using a complicated SELECT statement with a CONCAT. Will this be
> possible with the abstracted class?
>
> Thanks for your consideration,
> FD
>
I usually implement this with a double abstraction.

The first is a database factory to provide concepts such as SQL query
support, database connection sharing, error handling, etc.

The second is a database interface implementation that isolates all the
SQL in one class. This implementation is the only class that
instantiates the factory and uses it.

This way, I can change database factories (to connect to different
databases) with ease and, since the interface implementation contains
all the SQL, there is only one file I need to scan to adjust for the
variances in the SQL languages. (e.g. limit 1 in MySQL vs. count = 1 in
Oracle)

Is abstracting the database communications (with a factory) and
abstracting the interfaces a good idea? I certainly think so. In fact,
abstracting all communications is a good idea in my book. I use it for
all my SOAP work too.

-david-

 

Navigation:

[Reply to this message]


Удаленная работа для программистов  •  Как заработать на Google AdSense  •  England, UK  •  статьи на английском  •  PHP MySQL CMS Apache Oscommerce  •  Online Business Knowledge Base  •  DVD MP3 AVI MP4 players codecs conversion help
Home  •  Search  •  Site Map  •  Set as Homepage  •  Add to Favourites

Copyright © 2005-2006 Powered by Custom PHP Programming

Сайт изготовлен в Студии Валентина Петручека
изготовление и поддержка веб-сайтов, разработка программного обеспечения, поисковая оптимизация