+1  A: 

It appears that your getDB function will only connect once because of this line:

if (!self::$objInstance){

So the first time you execute it, it will connect, but on all subsequent calls the logic is ignored.

I suggest adding another property to your class that stores the current DBType and changing your conditional to:

if (!self::$objInstance || $DBtype != self::$dbtype){

You would have to set $dbtype inside each case of the switch statement.

Fosco
Thanks Fosco! Let me try to remove that line and see how it goes :)
Ticabo
Great idea, Fosco. The only problem is that the DBtype doesnt distinguish the DB :( I am working with many MySQL DBs and some MSSQL ones and an Oracle one. More may also be added later...
Ticabo
ok then some combination of dbtype and dbindex?... you get the idea, though, right?
Fosco
Yes, Fosco! I get the idea. Im very grateful for the help. Ircmaxwell gave a similar suggestion, combining dbtype and dbindex :) The only problem is that I cant quite wrap around the PDO object / array stuff yet (I know very little OOP as at now). Thanks again.
Ticabo
+1  A: 

You have it setup as a singleton. So your next call to Db::getDB returns the original instance. If you want to cache the instances for the duration of the script, change $objInstance to an array, and then instead of doing:

if (!self::$objInstance){

Do

$signature = $DBtype . $DBindex;
if (!isset(self::$objInstances[$signature])) {

Of course you'll need to change the assignment lines and the return line as well, but I think you get the idea...

ircmaxell
Thanks, ircmaxell. I think this may work, but right now it declares, referencing that code I just added:Fatal error: Cannot use object of type PDO as array in C:\apache\htdocs\ticabo\includes\db.class.php on line 29
Ticabo
What do you suggest please?
Ticabo
As I said, you'll need to change the assignment lines as well (and the return line). So instead of doing `self::$objInstances = new...` and `return self::$objInstances;`, you'll need to do `self::$objInstances[$signature] = new...` and `return self::$objInstances[$signature]` respectively...
ircmaxell
Yay!!! It worked like magic!!! Thanks!!!! You're the man! Now I really need to learn OOP. :-)
Ticabo
Well, that's not really OOP. That's just storing things in an array dynamically... But glad I could help...
ircmaxell