Jump to content

Recommended Posts

I have a class to handle DB communication doing something like

 

$sql = new Sql();
$sql->query($foo);

It handles a few things I need before and after queries and also handles results the way I need it.

 

My question is, I was thinking about putting a mysql_connect() and mysql_close() inside the query function, for convenience, would that be wrong? The server will be handling 10 to 20 connections tops, in case that's relevant.

 

Thank you.

Link to comment
https://forums.phpfreaks.com/topic/202866-using-mysql_connect-before-each-query/
Share on other sites

Put it inside the class constructor, not the query statement. Opening and closing mysql connections every time a query is ran will cause an unneeded burden on your server. Infact you do not need to call mysql_close at all. As the connection is automatically closed by php after processing.

 

But I would highly suggest against putting the connection string and opening / closing connections for each query. It is unnecessary and will cause more trouble then it is worth.

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.