PHP: How Do I Get a MySQL Link Identifier For an Already Open Connection?

Solution 1

Thanks to everyone for the replies.

I ended up opening my own connection, and when my plug-in was done, the last line reopens the initial connection so the rest of the main script can use the database it expects. It's sloppy, I know, but it doesn't seem like there's a better option in this case. :/

Update:: I've submitted this as a feature request on php.net. The link is: http://bugs.php.net/bug.php?id=49400

Solution 2

Even though the explanation of Anti Veeranna is correct, there is a very straight-forward way to do what you want. If you were to read the documentation for mysql_connect(), you would find out that this function has a 4th parameter, "new_link" , which is false by default. If you call mysql_connect() again with the same parameters, which is probably the case, it would not create a new connection, but instead would return the resource identifier of the old one.

Any time ;)

Solution 3

No, there isn't. You have to record link identifiers yourself. You could define link identifier as a class property, so that you can easily access it from your methods and don't have to worry about passing it as a variable over and over again.

Share:
Admin
Author by

Admin

Updated on June 13, 2022

Comments

  • Admin
    Admin about 2 months

Related