Jump to content

Using mysql_connect() before each query?


Hioushi

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.

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.