Welcome to WebmasterWorld Guest from 54.226.246.160

Forum Moderators: open

Message Too Old, No Replies

When (where) to mysqli close($mysqli);

     

rigaconnect

9:34 am on Feb 6, 2013 (gmt 0)



I need to validate username if it already exists in database.
I connect to database, validate.

Then other php code

Then again I need to validate email if it already exists in database.

Is it necessary to close connection after each query? mysqli_close($mysqli);

Or I can close one time at bottom of file when I know that latter would not be necessary to connect to database.

I mean for security reasons. If i close at bottom of file, are there exist some security problems?

whoisgregg

5:41 pm on Feb 11, 2013 (gmt 0)

WebmasterWorld Senior Member whoisgregg is a WebmasterWorld Top Contributor of All Time 10+ Year Member



Opening a connection is an expensive operation. You should only close the connection when you are sure it won't be used again.

However, open connections are automatically destroyed at the end of script resolution. So, although calling mysqli_close() will free up those memory resources for the rest of the script, it's not actually a requirement to call that function at all.

rigaconnect

6:02 pm on Feb 11, 2013 (gmt 0)



ok, thanks!
 

Featured Threads

Hot Threads This Week

Hot Threads This Month