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 <?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.
php
require_once('dal/Factory.php');
$factory = Factory::getInstance();
the above file also uses a file called constants.php.
which looks like this.
php
<?php
define('DATABASE', 'mysql');
?>
We will discuss what it is used for later.
the rest will follow later.