homepage Welcome to WebmasterWorld Guest from
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Pubcon Platinum Sponsor 2014
Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderator: open

Databases Forum

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

Msg#: 4542889 posted 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?



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

Msg#: 4542889 posted 5:41 pm on Feb 11, 2013 (gmt 0)

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.


Msg#: 4542889 posted 6:02 pm on Feb 11, 2013 (gmt 0)

ok, thanks!

Global Options:
 top home search open messages active posts  

Home / Forums Index / Code, Content, and Presentation / Databases
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Home ¦ Free Tools ¦ Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About ¦ Library ¦ Newsletter
WebmasterWorld is a Developer Shed Community owned by Jim Boykin.
© Webmaster World 1996-2014 all rights reserved