View Single Post
Old 11-09-2007, 10:55 AM   #15 (permalink)
Tanax
The Prestige
Upcoming Programmer Inquisitive 
 
Tanax's Avatar
 
Join Date: Sep 2007
Location: Sweden, Stockholm
Posts: 1,053
Thanks: 115
Tanax is on a distinguished road
Default

Quote:
Originally Posted by sketchMedia View Post
Sorry my brain cant compute (out of coffee here atm :( )

what it looks like to me is that u want to know how you would extend the script to include, for example, oracle?

like this:
PHP Code:
switch($type
{

    case 
'mysql':
        include_once(
'DBmysql.php');
        
self::$DB = new DBmysql();
        break;

    case 
'mssql':
        include_once(
'DBmssql.php');
        
self::$DB = new DBmssql();
        break;
        
    case 
'oracle':
        include_once(
'DBoracle.php');
        
self::$DB = new DBoracle();
        break;

    default:
        include_once(
'DBmysql.php');
        
self::$DB = new DBmysql();
        break;


btw i removed the
PHP Code:
'DB'.$type.'.php' 
in the includes because
lets say, $type = 'oracle' u dont really need concat the value of type into the include as its a switch so type will always be equal to 'oracle' otherwise it wouldnt have fired that line if you get my drift.

If this doesnt answer your question, i must be having one of my 'dense' days again and i shall go and beat myself with a fish until my brain gets running again.
Ofcourse, but when I coded it was easier to just copy
PHP Code:
'DB'.$type.'.php' 
to every line ;)

Anyhow, let's say you have just a normal mysql class in database.php
In index.php you need to include the database.php in order to create an instance of that object:
PHP Code:
include_once('database.php');
$db = new database(); 
because if you don't include it, then you can't create the database object.
You with me so far?


And now, I have this factory, in a file called DB.php
And each of the database classes is in DIFFERENT files:
DBmysql.php
DBmssql.php
DBoracle.php

But in my DB.php, I haven't included them, because I only want to include the one I will use for my instance of the object.

So, if I have
PHP Code:
$db DB::getType('oracle'); 
this line will execute in DB.php:
PHP Code:
case 'oracle':
self::$DB = new DBoracle();
break; 
But in order to create the new DBoracle object, we need to include the file, which holds that class.

And that's where my question comes in.
How will I include it, like I said before?
PHP Code:
case 'oracle':
include_once(
'DBoracle.php');
self::$DB = new DBoracle();
break; 
And would that be the best way to include it?
Tanax is offline  
Reply With Quote