Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
Thread: Opening a mysqli connection
07-25-2012, 10:52 PM #1
- Join Date
- May 2007
- Thanked 0 Times in 0 Posts
Opening a mysqli connection
Hi all, I'm just wondering when is the best time to open a mysqli connection? Previously when using mysql I would connect once in the config of each page and naturally I would have simply put $db = new mysqli( configdetails ); at the top of every page.
However I've seen a lot of examples saying that with mysqli you should connect each time you need to use it, and then close the connection when you're done. every time.
What would you do? opening multiple connections per page over and over again seems like it would eat up resources far quicker than 1 connection per page, and probably be more difficult to manage the code?
Any views appreciated!
07-25-2012, 11:38 PM #2
- Join Date
- Jun 2008
- New Jersey
- Thanked 259 Times in 256 Posts
Uh... can you show an example of something that mentions creating a new connection every time its needed? I've never heard of that, best as i know, its inefficient, but I will gladly admit I'm not a great resource for efficiency.