View Full Version : Opening a mysqli connection

07-25-2012, 10:52 PM
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
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.