2

I have a code which Creates a Database Connection as Follows.

$dbConn = new mysqli($dbHost, $dbUserName, $dbUserPasswrd, $database);  

$strSQL = 'SELECT * 
             FROM Table_Name';

$stmt   = $dbConn->prepare($strSQL);
$stmt->execute();

$stmt->close();
$dbConn->close();

I have created a php page where i call this code.

Now when I see the connections in mysql database using toad GUI it is showing 1 connection during the first time the page loads and count keeps on increasing when the page get refreshed.

1.Why the no of connections increase despite I have mysqli close at the end of code

2.Does using $dbConn->close() help in optimizing performace of DB by reducing no of unused connections

Please explain in brief so everyone can learn some.

enter image description here

Thanks for Reply

1
  • Did you look up what the variable "connections" means? I suspect it is the total of connections that has been made is, so apart from them being closed or not. Commented Dec 10, 2012 at 10:17

1 Answer 1

1

https://dev.mysql.com/doc/refman/5.5/en/server-status-variables.html says:

Connections: The number of connection attempts (successful or not) to the MySQL server. Threads_connected: The number of currently open connections.
I.e. connections counts all attempts to connect that have been made while threads_connected is probably the value you are interested in.

Sign up to request clarification or add additional context in comments.

6 Comments

Thanks for Reply. I tried by running show status like '%onn%'; But there is no change in Threads_connected List
"But there is no change in Threads_connected List" - please elaborate. It's rather unlikely that you request the variables just in that brief moment when your php script "holds" a connection to the server.
I tried to run the page after putting in local domain 192.168.1.18/sample.php I accessed the URl from three different system. The Threads_connected remains the same
So it's not increasing, your question has been answered? 1. because "connections" is the total number of connections (attempts) that were made, the currently open connection counter does not increase, 2. yes mysqli::close() closes the connection to the server.
No I removed my code $dbConn->close(); and then also it remains the same.
|

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.