StephanieT Posted January 16, 2019 Share Posted January 16, 2019 (edited) 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)! Edited January 16, 2019 by StephanieT Quote Link to comment Share on other sites More sharing options...
requinix Posted January 16, 2019 Share Posted January 16, 2019 "Multiton" is a common term for this. The obvious answer seems too obvious: $connections = array( "mysql1" => new PDO(...), "mysql2" => new PDO(...), "postgres1" => new PDO(...), ... ); $connections["mysql2"]->whatever(); Quote Link to comment Share on other sites More sharing options...
StephanieT Posted January 16, 2019 Author Share Posted January 16, 2019 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. Quote Link to comment Share on other sites More sharing options...
requinix Posted January 16, 2019 Share Posted January 16, 2019 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? Quote Link to comment Share on other sites More sharing options...
benanamen Posted January 16, 2019 Share Posted January 16, 2019 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.