Jump to content

Recommended Posts

Hey everyone. I'm running a site engine with a bunch of different queries, maybe around 25 queries per page view. I am planning to expand to a site with around 100+.

This isn't huge... but I'm just wondering, is it better to do a connect and close mysql command before and after EACH query, or is it better to do one connect command at the beginning of page execution and a close command at the end?

I'm curious about security and efficiency. Is doing more queries a lot more intensive on the server, and if I do one connect and one close is that leaving myself open to attacks?

Thanks,
-Will
Link to comment
https://forums.phpfreaks.com/topic/9981-more-connects-better-or-less/
Share on other sites

I'll tell you right now that is more effecient to open one connection at the beginning of the page and close it at the end of the page then it is to open and close a new connection for each query. I'm not sure about security, but I don't think you'll have a problem using just one connection per page instead of one connection per query.

[!--coloro:#990000--][span style=\"color:#990000\"][!--/coloro--]Jeremy[!--colorc--][/span][!--/colorc--]
[!--quoteo(post=375147:date=May 19 2006, 12:43 AM:name=jeremywesselman)--][div class=\'quotetop\']QUOTE(jeremywesselman @ May 19 2006, 12:43 AM) [snapback]375147[/snapback][/div][div class=\'quotemain\'][!--quotec--]
I'll tell you right now that is more effecient to open one connection at the beginning of the page and close it at the end of the page then it is to open and close a new connection for each query. I'm not sure about security, but I don't think you'll have a problem using just one connection per page instead of one connection per query.

[!--coloro:#990000--][span style=\"color:#990000\"][!--/coloro--]Jeremy[!--colorc--][/span][!--/colorc--]
[/quote]

OK, thanks a lot.
This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.