Page 2 of 2

Re: YADAL - Yet Another Database Abstraction Layer

Posted: Fri Feb 20, 2009 6:47 pm
by alex.barylski
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 :)

EDIT | http://code.google.com/p/pdowrapper/

Cheers,
Alex

Re: YADAL - Yet Another Database Abstraction Layer

Posted: Sat Feb 21, 2009 1:31 am
by Christopher
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.

Re: YADAL - Yet Another Database Abstraction Layer

Posted: Wed Apr 01, 2009 1:47 am
by thinsoldier
But in relation to the original post:

Code: Select all

else if(defined('CALLING_WEBAPP_NAME'))
      {
          global $SESSION_GLOBALS;
          $host = (isset($SESSION_GLOBALS[CALLING_WEBAPP_NAME]['host'])) ? $SESSION_GLOBALS[CALLING_WEBAPP_NAME]['host'] : 'localhost';
          $username = $SESSION_GLOBALS[CALLING_WEBAPP_NAME]['user'];
          $password = $SESSION_GLOBALS[CALLING_WEBAPP_NAME]['password'];
          $db = $SESSION_GLOBALS[CALLING_WEBAPP_NAME]['db'];
      }
I've done something like this before.
We call ours $CONFIG instead of $SESSION_GLOBALS.

What I did once was to have my constructor do nothing.
Then immediately call whatever startup function I wanted.

Code: Select all

$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');

Re: YADAL - Yet Another Database Abstraction Layer

Posted: Wed Apr 01, 2009 4:56 pm
by thinsoldier
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?

Re: YADAL - Yet Another Database Abstraction Layer

Posted: Wed Apr 01, 2009 5:27 pm
by pickle
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.