Multiple MySql connections
[email protected] (Alexander Meurer)
| Newsgroups | php.version4 |
|---|---|
| Message-ID | <[email protected]> |
Hi,
I wrote a little test script, to find out how to use multiple database
connections.
Both functions (OutputA and OutputB) do exactly the same, but OutputA
calls
OutputB while the database connection in OutputA is open.
The strange thing is, that both $dbh variables get the value 1 and the
"mysql_close($dbh)" statement in OutputB closes _both_ connections, so
the
select statement in OutputA fails.
Is this a bug? I expected that the $dbh variable in OutputB gets another
value.
I replace the mysql_connect by mysql_pconnect and _this_ works as I
expected.
Can anybody comment this please.
Thanks for any help
Alex
P.S.: Here is the script:
<?php
function OutputB () {
$dbh = mysql_connect ("dbserver", "dbuser", "dbpasswd");
echo " DB handle: $dbh<br>\n";
$sth = mysql_db_query ("resman", "select name from user where
id=4");
list ($name) = mysql_fetch_row ($sth);
echo " user name: $name<br>\n";
mysql_close ($dbh);
}
function OutputA () {
$dbh = mysql_connect ("dbserver", "dbuser", "dbpasswd");
echo "DB handle: $dbh<br>\n";
OutputB ();
mysql_select_db ("resman", $dbh);
$sth = mysql_query ("select name from user where id=4", $dbh);
list ($name) = mysql_fetch_row ($sth);
echo "user name: $name<br>\n";
mysql_close ($dbh);
}
OutputA ();
?>