Login or Sign Up to become a member!
LessThanDot Sit Logo

LessThanDot

Web Developer

Less Than Dot is a community of passionate IT professionals and enthusiasts dedicated to sharing technical knowledge, experience, and assistance. Inside you will find reference materials, interesting technical discussions, and expert tips and commentary. Once you register for an account you will have immediate access to the forums and all past articles and commentaries.

LTD Social Sitings

Lessthandot twitter Lessthandot Linkedin Lessthandot friendfeed Lessthandot facebook Lessthandot rss

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

Your profile

Authors

Search

XML Feeds

Google Ads

« Nice article on ASP.NET MVCDear PHP-God(s)(ess)(esses) »
comments
Rate Post:
submit to reddit Digg!FacebookDotnetkicks

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.

  1. <?php
  2. include_once( ‘constants.php’ );
  3. require_once( ‘factory/DatabaseFactory.php’ );
  4.  
  5. class Factory
  6. {
  7.    function getInstance ()
  8.    {
  9.         static $instance;
  10.         if (!isset($instance))
  11.         {
  12.             $c = __CLASS__;
  13.             $instance = new $c;
  14.         }
  15.         return $instance;
  16.    }
  17.    
  18.    function getFactory()
  19.    {
  20.     return dataBaseFactory::getInstance();
  21.    }
  22. }
  23. ?>

this factory is a singleton and can be called as such.

Something like this will do.

  1. require_once(’dal/Factory.php’);
  2. $factory =  Factory::getInstance();

the above file also uses a file called constants.php.

which looks like this.

  1. <?php
  2. define(‘DATABASE’, ‘mysql’);
  3. ?>

We will discuss what it is used for later.

the rest will follow later.

About the Author

User bio imageChristiaan is a forensic technician who programs on the side, although my function description says that I do IT-things for 90% of the time . I'm an avid VB.NET fan and I use lots of the ALT.Net techniques, like unit-testing, nhibernate, logging, IoC, ...
Social SitingsTwitterLinkedInHomePageLTD RSS Feed
714 views
submit to reddit Digg!FacebookDotnetkicks

Comments and Feedback

No feedback yet

Leave a comment


Your email address will not be revealed on this site.

Your URL will be displayed.
(Line breaks become <br />)
(Name, email & website)
(Allow users to contact you through a message form (your email will not be revealed.)