Re: What is wrong with next code
| From: | Vladimir Shiray | Date: | Fri, 29 Oct 2004 14:44:27 +0000 |
| Subject: | Re: What is wrong with next code | ||
| References: | 1 2 | Groups: | php.general |
| Request: | Send a blank email to php-general+get-200645@lists.php.net to get a copy of this message | ||
I has noted specially:
It works OK in PHP 4.3.6 or when line "$db2 = 0;" had been commented
in all described versions of PHP.
So next example works perfect:
-------------------------------------------------
error_reporting(E_ALL);
$db1 = mysql_connect ('localhost', 'test', '1');
$db2 = mysql_connect ('localhost', 'test', '1');
mysql_close($db2);
$result = mysql_query('SELECT 1+1', $db1);
if ($result)
{
$row = mysql_fetch_row($result);
echo "Result: {$row[0]}\n";
}
-------------------------------------------------
root@gate:~/src/PHP# php -q mysql_connect3.php
Result: 2
On Thu, 28 Oct 2004 23:08:39 -0400
John Holmes <holmes072000@charter.net> wrote:
> Vladimir Shiray wrote:
> > -------------------------------------------------
> > Warning: mysql_query(): 4 is not a valid MySQL-Link resource in ...
> > $result = mysql_query('SELECT 1+1', $db1);
> > -------------------------------------------------
> [snip]
> > $db1 = mysql_connect ('localhost', 'test', '1');
> > $db2 = mysql_connect ('localhost', 'test', '1');
> > mysql_close($db2);
>
> If you connect with the same parameters, PHP will just reuse the
> previous connection. So you only have one connection and closing either
> one will result in the connection being lost, hence the "invalid link
> resource" message.
>
> --
>
> ---John Holmes...
>
> Amazon Wishlist: www.amazon.com/o/registry/3BEXC84AB3A5E/
>
> php|architect: The Magazine for PHP Professionals _ www.phparch.com
>
>