Jump to content

How to handle multiple connections using a single class instance


StephanieT

Recommended Posts

Hi All

 

I have not really played around with PHP in ages so I am having a hard time trying to figure out the best way to proceed. Anyhow... what I need to get done is to take a singleton pattern core database class that has a extended driver based class (ie; the type of database server the connection is connecting to), and build a new class that dynamically handles as many driver based connections that are called using a single instance. As a side note, I tried PDO but it only supports a single driver per class instance, and then each of those connections cannot not have their on set of properties that relate to each connection. Anyway, I was thinking that the best way to handle all the driver specific connections, is to hand out a 'unique hash reference' that points to an array of connection objects and the object properties. then when the client runs any sql function they pass the 'unique hash reference'  which the class then returns the object and it properties that will be used by the class to call up the driver specific sql function that was requested by the client. So what do you all thing about that....

 

TIA

stephanieT

 

PS...

 

I reason i need this is because I need to update up 25 different databases based on data stored on all the databases and  not all of the database servers are of the same type, (ie; MSSQL, Oracle, MySQL, MariaDB, berkeley DB, postgres, sqlite2,3, etc, etc)!

Link to comment
Share on other sites

Hi

 

thanks for that, but the problem with that is that each 'new instances();' won't have direct access to the connection resource(s) / object(s) of the other 'new instances();' , so if one of those 'new instances();' encounters a error, whether it be a simple query error or a connection error or a fatal error, there will be no way for me to gracefully handle that error in each of those other 'new instances();'! And I really need to handle those errors across each connection because I am dealing with transitions, so i need a way to make sure I either fully complete the transition, (ie either, commit or rollback), each of those transitions, because if I don't, database access to those tables on some of the database servers that I am running those transitions on are staying locked and become completely inaccessible because they are waiting for the transition to finish, and it never will, and they remain that way, until a full server restart.

Link to comment
Share on other sites

And that sounds like a different problem. The issue of how you can store and access multiple connections is easy.

PDO doesn't have a way to send errors to other PDO instances. Doesn't exist. So you'll have to come up with something to do it. How depends a lot on aspects of your system that I can't see, nor can really understand from your descriptions, but at some point it's going to boil down to needing to have all the connections available and an array can do that.

How about this. What kind of code do you want to write that will need to make use of this thing?

Link to comment
Share on other sites

17 hours ago, StephanieT said:

I reason i need this is because I need to update up 25 different databases based on data stored on all the databases and  not all of the database servers are of the same type, (ie; MSSQL, Oracle, MySQL, MariaDB, berkeley DB, postgres, sqlite2,3, etc, etc)!

Could you please provide more information about this, as this is the "real" problem. You have been asking for help with your attempted solution to this. Let us decide what the solution should be. To properly do that we need to know all about the above.

Link to comment
Share on other sites

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.