Jump to content

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

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.