View Single Post
Old 03-31-2009, 05:16 PM   #1 (permalink)
Tanax
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,080
Thanks: 115
Tanax is on a distinguished road
Default DB wrapper for framework

Hi!

I got really interested in frameworks, especially the MVC pattern, so I followed a tutorial on how to create an own framework. Works great! Only one thing, or well, actually I have a couple of questions, but let's just take first thing's first.

The tutorial showed how to create a Database class, but that was only for MySQL. I'm only using MySQL so for me it won't be a problem, but I would love to learn how to create some kind of wrapper instead. So that it gets the desired DB engine(ofcourse you have to write seperate classes for each engine) based on what the user writes in the configuration file.

Right now it's used like this:
my bootstrap file:
PHP Code:
require_once LIBPATH 'Database' EXT
then inside the default Controller(the one which all the rests will extend):
PHP Code:
$this->db =& load_class('Database'); 
Is there any way I can .. when I load the Database class, it checks the configuration for what db engine, include the specified engine class, instanciate it, and return it?

Basicly, I want the $this->db to become an instance of DBmysql if that's specified, so that the Database class only works like a.. wrapper or gateway?

Or will I have to do this in another way for it to work?

EDIT: I already have functions to check if a config item is set. I only need help with the actual Database wrapper and how to accomplish so $this->db becomes instance of the specified engine
__________________
Tanax is offline  
Reply With Quote