Coding Critique is the place to post source code for peer review by other members of DevNetwork. Any kind of code can be posted. Code posted does not have to be limited to PHP. All members are invited to contribute constructive criticism with the goal of improving the code. Posted code should include some background information about it and what areas you specifically would like help with.
Popular code excerpts may be moved to "Code Snippets" by the moderators.
I did something similar a while back but used PDO as the database 'access' layer
A database 'abstraction' layer (would be IMHO) an API that abstracted you from any particular DBE, such as the differences between MSSQL and MySQL when it comes to SELECT and so forth.
Nice work - always interested in seeing how others skin the cat
pickle wrote:It is quite useful actually. Say, for example, I've got a calendar of events, with each event being it's own object. Each Event object needs to access the database to retrieve it's information. With a singleton DAL, each unique Event object uses the same database connection, rather than making one connection for each object.
But because it only allows you to do one connection per class, I think it is better to use another mechanism -- like Corbyn's registry -- to achieve this functionality.
$obj = new tooMuchStuffInOneClass();
$obj->setupFromCONFIG($CONFIG); // sometimes there'll be a redefined CONFIG in the current file
// $obj->setupFromCONFIG(); // this will global the original CONFIG set in the central include file
// or normal usage
// $obj->construct('tubetop','salami','bodyswing');
pickle wrote:It is quite useful actually. Say, for example, I've got a calendar of events, with each event being it's own object. Each Event object needs to access the database to retrieve it's information. With a singleton DAL, each unique Event object uses the same database connection, rather than making one connection for each object.
What if the Events area of your site is to allow Events to belong to (multiple?) event categories. So you have a categories table and another table that shows which event records belong to which event categories. How do you approach that?
And is there a common naming convention for these in-between tables that link one table to another?
thinsoldier wrote:What if the Events area of your site is to allow Events to belong to (multiple?) event categories. So you have a categories table and another table that shows which event records belong to which event categories. How do you approach that?
And is there a common naming convention for these in-between tables that link one table to another?
I think that's getting into the realm of database design. How you design the database & queries is separate from these classes.
Real programmers don't comment their code. If it was hard to write, it should be hard to understand.