I have a class for each database table object. Each class takes care of connection/queries/data format (database table specific logic) as I prefer to assign a connection for each class for better modularity. Also, I am using specific connections for some tables and queries.
My question is how can I check if a connection already exists so it won’t start another one?
Basically I want to check if the connection with the same username/password/database has already been made. Or is this not necessary because mySql won’t start a new connection for the same user? If that is so then please explain.
After further research found out that this is not possible … it would require to get the thread id and use the conn with the thread id and it would act like a persistant conn; Or it would require to keep track every thread ids used during a script and it’s kinda useless.
There isn’t yet a spimple method of doing this … persistant connection can be a choice but then u have to take care of connection clean up and again sux 🙂
P.S. : Eventually i did made a tracking system for the connections during my app run (the guys that said to store them in a globally available object we’re right). Stored conn object and conn params in 2 arrays in a singleton class object, checked if the params allready exists in params array , if not make new conn , if yes get the conn object from the array-key thats the same with the key where params were found… I allready had the arhitecture made for this but didnt want to use that class…not the logic i began with :), and also wanted to make it in a library item, thats why i was looking for a simple and abstract solution but there is only a particular solution 🙂
too may connectionserror.I suggest use singleton pattern and some OO.