homepage Welcome to WebmasterWorld Guest from 54.227.11.45
register, free tools, login, search, pro membership, help, library, announcements, recent posts, open posts,
Become a Pro Member

Home / Forums Index / Code, Content, and Presentation / Databases
Forum Library, Charter, Moderators: physics

Databases Forum

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




msg:4542891
 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




msg:4544614
 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.

rigaconnect




msg:4544631
 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