Multiple MySql connections

From: Date: Wed, 24 May 2000 12:50:29 +0000
Subject: Multiple MySql connections
Groups: php.version4 
Request: Send a blank email to php-version4+get-15659@lists.php.net to get a copy of this message
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 "&nbsp;&nbsp;DB handle: $dbh<br>\n"; $sth = mysql_db_query ("resman", "select name from user where id=4"); list ($name) = mysql_fetch_row ($sth); echo "&nbsp;&nbsp;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 (); ?>

« previous php.version4 (#15659) next »