CodeIgniter Forums
Simple Database Connect Question - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Archived Discussions (https://forum.codeigniter.com/forumdisplay.php?fid=20)
+--- Forum: Archived General Discussion (https://forum.codeigniter.com/forumdisplay.php?fid=21)
+--- Thread: Simple Database Connect Question (/showthread.php?tid=4958)



Simple Database Connect Question - El Forum - 12-27-2007

[eluser]tokyotoejam[/eluser]
Ok. I am building a social network site which is almost in beta. The profile page for example runs queries to grab comments, blogs, top friends, profile pic, etc. Thats several good queries for just one page.

I have DB connecting automatically in config.

So here is the question.
Does the db connect only once per start of page, run all queries, and then close once page is processed OR does the DB connect each time I do a $this->db-get(),insert,yada yada and close at the end of each method call resulting in 5 or 6 connections per page?

What is the recommended way of doing this per page, so that if the website get hit BIG time it will handle it?


Simple Database Connect Question - El Forum - 12-27-2007

[eluser]jcopling[/eluser]
This would be directly related to the 'pconnect' setting inside the database config file.

Depending on which database you use, having 'pconnect' set to true should retain a persistent connection throughout.

I say depending on which db you use because I have read that MSSQL databases do not behave correctly with a persistent connection.


Simple Database Connect Question - El Forum - 12-27-2007

[eluser]tokyotoejam[/eluser]
I am using good ol MySQL.


Simple Database Connect Question - El Forum - 12-27-2007

[eluser]tokyotoejam[/eluser]
So can anyone answer if CI reconnects for each $this->db->get ??? or once per page???


Simple Database Connect Question - El Forum - 12-27-2007

[eluser]tonanbarbarian[/eluser]
As far as I am aware CI connects once per page only
persistent connections allow PHP to use a pool of connections that have been used by previous page requests thereby saving connection time


Simple Database Connect Question - El Forum - 12-27-2007

[eluser]tokyotoejam[/eluser]
Thanks tonan, that clarifies things for me. I was hoping that it only connected once per page Smile