Re: Abstracting a database class
Available news archives: comp.lang.tcl - comp.lang.python - comp.security.firewalls - sci.crypt - comp.lang.php - comp.lang.javascript
Google
 
Web news.hping.org


comp.lang.php archive

Re: Abstracting a database class

From: Chung Leong <chernyshevsky@hotmail.com>
Date: Wed Jan 04 2006 - 02:59:49 CET

Full Decent wrote:
> I like this idea and the possibility of running "DB queries" against a
> real DB, the filesystem, or the network. Do you know of existing
> classes that provide this level of abstraction beyond ADODB?

It's just a matter of separating the concerns of your code. Doesn't
really require special logic. For example, say you need to retrieve a
article from the database, instead of running the query in the
application code itself, call a function to do it:

$message = GetMessageById($id);

or

$message = GetMessageByTitle($title);

or

$messages = GetMessagesByDate($start, $end);

If you want to get fancy, use a class factory

$messages = $message_factory->Load($criteria, $offset, $length);

There are many ways to do this. The bottomline is to isolate the data
save/retrieval code, so that you can swap in a different mechanism by
simply including a different file.
Received on Tue Jan 17 16:52:13 2006