TalkPHP

TalkPHP (http://www.talkphp.com/forums.php)
-   Advanced PHP Programming (http://www.talkphp.com/advanced-php-programming/)
-   -   DB wrapper for framework (http://www.talkphp.com/advanced-php-programming/4086-db-wrapper-framework.html)

Tanax 03-31-2009 05:16 PM

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


All times are GMT. The time now is 11:00 PM.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.
Search Engine Optimization by vBSEO 3.1.0