Re: Getting database name from link identifier
| From: | Curtis Maurand | Date: | Wed, 26 Feb 2014 01:17:15 +0000 |
| Subject: | Re: Getting database name from link identifier | ||
| References: | 1 2 3 4 5 6 7 8 9 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-322992@lists.php.net to get a copy of this message | ||
On 2/25/2014 5:22 PM, Aziz Saleh wrote:
On Tue, Feb 25, 2014 at 5:21 PM, Larry Martell <larry.martell@gmail.com>wrote:|<?php function mysql_current_db() {On Tue, Feb 25, 2014 at 5:15 PM, Larry Martell <larry.martell@gmail.com> wrote:You are welcome. Glad it worked out. Also there is this:On Tue, Feb 25, 2014 at 5:09 PM, Aziz Saleh <azizsaleh@gmail.com> wrote:wrote:On Tue, Feb 25, 2014 at 4:59 PM, Larry Martell <larry.martell@gmail.com wrote:On Tue, Feb 25, 2014 at 4:53 PM, Aziz Saleh <azizsaleh@gmail.com>larry.martell@gmail.com>On Tue, Feb 25, 2014 at 4:47 PM, Larry Martell <from awrote:On Tue, Feb 25, 2014 at 4:41 PM, Aziz Saleh <azizsaleh@gmail.com> wrote:On Tue, Feb 25, 2014 at 4:28 PM, Larry Martell <larry.martell@gmail.com> wrote:Is there any way to find out what database I am connected tobe.link identifier? I have some code this does this: @ $db = mysql_pconnect($dbserver, $dbuser, $dbpass); @ mysql_select_db($dbname, $db); I know at the time this is executed $dbname is what I want it todifferentBut later on when I pull data using $db, I get data from awhyThanks! Indeed I am not 'using' the db that $dbname is set to when I execute the mysql_select_db command. Now I just have to figure outdatabase. If I try to echo $db at the time of the query I get "Resource id #5". Can I get the database name from $db?You won't be able to, you will need to execute a query on that DB connection handler to check the DB name currently used: SELECT DATABASE() as DB_NAMEyourthat is.Are you making a call to mysql_select_db besides the above duringbecode execution (even on a different DB handler)? If yes, then that woulddifferentIs it safe to assume that that all of those 23 connections havethe issue since.I was simplifying the code for purposes of asking the question. Actually the app connects to 23 different databases on different servers. The link identifiers are stored in an array. Each mysql_select_db is called with a different link identifiers. I am echoing out the link identifiers and the array index when I create them and also when I use them. I see that the index is the same, the resource id # is the same, but I'm connected to a different db then the one I called mysql_select_db with.users whohost/user/password combination?No, there are multiple connections on each server.I ran into issues before, where changing the database using the mysql_select_db function changed the db for the connection for allcgi.are sharing that connection - PHP was running as apache module and notnewI ended up using mysql_connect with the third param as true to force aThat indeed was it. I changed to mysql_connect with new_link true and the issue went away. Thanks very much!connection.I'm using mysql_pconnect, which does not have the new_link param. Sounds like you've hit the problem I'm having. I'll try changing to mysql_connect with new_link true and see if that fixes it.
$r= mysql_query("SELECT DATABASE()") or die(mysql_error());
return mysql_result($r,0);
}
?>|