Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

Tags:

php

mysql

When you open a MySQL connection with mysql_connect(), it returns a link identifier. But what if you want to get that link identifier again later in the script? (for example: A plug-in, that needs to open a new database connection, and still access the old one.)

I'm looking for a way to return a link identifier to the last connection opened by mysql_connect(). Is there a function that does this?

like image 540
Nick Avatar asked Jan 23 '23 06:01

Nick


1 Answers

Even though the explanation of Anti Veeranna is correct, there is a very straight-forward way to do what you want. The docs for mysql_connect() state 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 ;)

like image 168
XedinUnknown Avatar answered Jan 25 '23 19:01

XedinUnknown