Since php supports OO I think we should follow the OO rules. SO I wrote a DAO layer like sun recommends it for it’s J2EE framework.
So lets start with the Factory. lets put it in a folder dal.
- <?php
- include_once( ‘constants.php’ );
- require_once( ‘factory/DatabaseFactory.php’ );
- class Factory
- {
- function getInstance ()
- {
- static $instance;
- if (!isset($instance))
- {
- $c = __CLASS__;
- $instance = new $c;
- }
- return $instance;
- }
- function getFactory()
- {
- return dataBaseFactory::getInstance();
- }
- }
- ?>
this factory is a singleton and can be called as such.
Something like this will do.
- require_once(’dal/Factory.php’);
- $factory = Factory::getInstance();
the above file also uses a file called constants.php.
which looks like this.
- <?php
- define(‘DATABASE’, ‘mysql’);
- ?>
We will discuss what it is used for later.
the rest will follow later.





LTD Social Sitings
Note: Watch for social icons on posts by your favorite authors to follow their postings on these and other social sites.