DB 'Getter' - Good/Bad idea?
Posted: Thu Jun 08, 2006 8:51 am
Hi,
I'm just trying to get into the whole programming patterns with PHP. I'm wondering if anyone has any experience with any patterns that use a DB 'Interface' class, and if it was a good idea? I'm trying to build an application that is meant to be expanded by others, so I'm trying to decide if it's worth it to add another layer to my application
ie. main->dbInterface->DBAL->presentation
The only benefit I can see is that others don't need to know SQL syntax, but don't most able developers know it anyway? If I was to use this interface, basic SELECT queries for example could be shown like:
It seems that this would be more intuitive, but if you need a relatively complex query, it can become
This would create the same query as writing
I guess what I'm asking is, do you think that it's worthwhile to have an interface that can construce SQL queries like this, or is it easier to just code them like normal. I should note that I think using the interface would make it easier to modify (change queries, DBAL, etc)
Anyway, thanks for reading
Sphenn
I'm just trying to get into the whole programming patterns with PHP. I'm wondering if anyone has any experience with any patterns that use a DB 'Interface' class, and if it was a good idea? I'm trying to build an application that is meant to be expanded by others, so I'm trying to decide if it's worth it to add another layer to my application
ie. main->dbInterface->DBAL->presentation
The only benefit I can see is that others don't need to know SQL syntax, but don't most able developers know it anyway? If I was to use this interface, basic SELECT queries for example could be shown like:
Code: Select all
$db->get(array('config_name', 'config_value'), 'config');Code: Select all
$db->get(array('config_name', 'config_value'), 'config', 'config_value', '3', '`config_name DESC`', '20');Code: Select all
SELECT config_name, config_value
FROM config
WHERE config_value = 3
ORDER BY `config_name` DESC
LIMIT 20;
Anyway, thanks for reading
Sphenn