Jump to content

check for connection


chiprivers

Recommended Posts

"Opens or reuses a connection to a MySQL server."
This makes me think if there is already a connection open, it will use that one. So you don't really need to check...

I always assign to a variable also. I wrap my database connection in a function for error handling, etc, and use pconnect.
Link to comment
https://forums.phpfreaks.com/topic/31711-check-for-connection/#findComment-146976
Share on other sites

The reason I am asking is that I am creating a group of functions that will extract and display information from my database.  I though it would be a good idea to check at the beginning of the function if there was an exisiting connection, else open a connection.
Link to comment
https://forums.phpfreaks.com/topic/31711-check-for-connection/#findComment-146978
Share on other sites

building on jesirose's interpretation: From the manual:
[quote]
If a second call is made to mysql_connect()  with the same arguments, no new link will be established, but instead, the link identifier of the already opened link will be returned.
[/quote]

so if you were to just do mysql_connect() in every one of your functions (or call a connection function with error handling, as jesirose suggested (which is what i do too)) , it will do what you want it to: open a new connection, or do nothing if it already exists
Link to comment
https://forums.phpfreaks.com/topic/31711-check-for-connection/#findComment-146981
Share on other sites

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.