Re: Re: [PHP General] RE: Problems with MySQL-Link [3:14370:14592]

From: Date: Fri, 01 Feb 2002 07:38:01 +0000
Subject: Re: Re: [PHP General] RE: Problems with MySQL-Link [3:14370:14592]
References: 1 2 3 4 5  Groups: php.general 
Request: Send a blank email to php-general+get-83075@lists.php.net to get a copy of this message
Hi! Thank you. But I cannot use that $link1 and/or $link2 to select two databases on different servers... If I use $link1 the first time to select the first database on the first server I got that error. But without that $link1-variable AND only one connection in the script it works. And it makes no sense if I use it as shell-prog or with Apache-Builtin-PHP. eg: #!/usr/local/bin/php -q <?php $link1 = mysql_connect("localhost","a"); echo 'Link 1: '.$link1 .'<BR>'; if (mysql_select_db("test", $link1)) { echo 'Successful select of test<BR>'; } else { echo 'Failed to select test<BR>'; } ?> gives this output: Warning: Supplied argument is not a valid MySQL-Link resource in /home/bt/bin/test.php on line 4 I don't know what to do... David Robley wrote:
In article <3C593BA5.10700@gmx.de>, b.tenhumberg@gmx.de says...
Hi! mysql_error returns nothing... The error arrives while selecting the database via: $link = mysql_connect("host","user","passwd"); mysql_select_db("bla", $link); echo $link returns always '1'! David Robley wrote:
In article <3C58FE54.6020903@gmx.de>, b.tenhumberg@gmx.de says...
So, I've testet all possible I found in my brain... CGI or Apache module: same error mysql_connect or mysql_pconnect: same error Variing settings in php.ini: same error How can I solve that problem? BTW: Here I describe it again: Connecting to a database works well: ok Working with that database: ok Using the additional $link-Parameter: false Not a valid resource id ... And it does not matter how many different links with different servers I use! The resource-id is always '1'. Strange...
Not a valid resource ID usually means a problem with the query - in fact this might be in the FAQ. Use mysql_error() after the database query to see if mysql returns a useful error.
Guess I misread your question. However, a litle playing around with this script <?php $link1 = mysql_connect("localhost","a"); $link2 = mysql_connect("localhost"); echo 'Link 1: '.$link1 .'<BR>'; echo 'Link 2: '.$link2 .'<BR>'; if(mysql_select_db("test", $link1)) { echo 'Successful select of test<BR>'; }else{ echo 'Failed to select test<BR>'; } if(mysql_select_db("test2", $link2)) { echo 'Successful select of test2<BR>'; }else{ echo 'Failed to select test2<BR>'; } ?> which gives this output Link 1: Resource id #1 Link 2: Resource id #2 Successful select of test Successful select of test2 seems to indicate that php is smart enough not to open a new link even if requested if there is already a link for the user! Removing the "a" in the first mysql_connect gives me two links with a resource ID of 1. I can force errors of course by feeding a wrong username/password which eventually leads to a 'Not a valid resource id' error but has other error messages as well. You aren't by chance hiding other error responses by using @ or 'or die'?
-- Berthold

« previous php.general (#83075) next »