Re: Re: [PHP General] RE: Problems with MySQL-Link [3:14370:14592]
| From: | David Robley | Date: | Thu, 31 Jan 2002 22:30:04 +0000 |
| Subject: | Re: Re: [PHP General] RE: Problems with MySQL-Link [3:14370:14592] | ||
| References: | 1 2 3 4 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-83014@lists.php.net to get a copy of this message | ||
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'?
--
David Robley
Temporary Kiwi!