Welcome Guest, Not a member yet? Register   Sign In
Mysql database Connection pooling with CI?
#1

[eluser]woracal[/eluser]
Has anyone implemented/used connection pooling with MySql through CI? Appreciate some comments.....
#2

[eluser]esra[/eluser]
You might do a forum search on 'load balancing' to see what you get. I believe there is at least one thread with one or more proposed solutions. Whether these handle connection selection in the same manner as pooled connections, I'm not sure (i.e., in the same way as Java for example).

It is possible to manually create connections, thus it should be possible to create a library with getConnection and setConnection methods based on the factory design pattern and handle the logic for connection pooling in the setConnection method. If you use a Base Controller approach where all your controllers are extended from a single controller, the base controller could load the factory and its methods would be available to all controllers inheirted from it.
#3

[eluser]woracal[/eluser]
Thanks Esra! Load balancing is also something im looking for in CI. Though, was a little worried about too many open connections to Mysql cos i'm hosted with a share host.... they allow only 50 concurrent connections to a db. I think I'll have to resort to load balancing as well....
#4

[eluser]esra[/eluser]
You need to spend some time reading the database library portion of the user guide. Read "Connecting to Multiple Databases" on this page.

http://ellislab.com/codeigniter/user-gui...cting.html

CI connections are assigned a name or DSN. Thus, you can reuse the same connections over and over again by referencing the existing named connections. You can do the same in Java, ASP and other programming environments. The trick is to use a get method that returns a reference to your pooled database objects (connections) which are available globally to your entire application. To do what you want, you only need to create a small number of database objects for the pool and reuse them as needed. If work leaves me alone, I will try to play with this over the weekend.




Theme © iAndrew 2016 - Forum software by © MyBB