Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 2 of 2
  1. #1
    Regular Coder
    Join Date
    May 2007
    Posts
    130
    Thanks
    9
    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!

  • #2
    Senior Coder
    Join Date
    Jun 2008
    Location
    New Jersey
    Posts
    2,546
    Thanks
    45
    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.


  •  

    Tags for this Thread

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •