Multiple instances of mysql_connect() in single PHP document.
| From: | Timothy Legg | Date: | Tue, 10 Nov 2009 21:14:57 +0000 |
| Subject: | Multiple instances of mysql_connect() in single PHP document. | ||
| Groups: | php.db | ||
| Request: | Send a blank email to php-db+get-46638@lists.php.net to get a copy of this message | ||
Hello,
Is it wrong to have mysql_connect() called twice within a single PHP
document, such as this? I have been running into some fairly annoying
query failures that commute when I change the order of these two blocks of
code. I am currently working around this by repeatedly using
mysql_select_db() to change the databases as I am needing to change to a
different database.
To be more specific, I can use the $db_material handle in doing a query,
but it will always try to search in the Labor_Log table and thus fail
because the tables have different and names. Swapping these blocks will
have a vice-versa effect.
//Connect to server (materials)
$db_material = mysql_connect("localhost", "root", "secret");
if (!$db_material)
{
echo( "<P>Unable to connect to the database server at this
time.</P>" );
exit();
}
mysql_select_db("Material_Log", $db_material);
//Connect to server (labor)
$db_labor = mysql_connect("localhost", "root", "secret");
if (!$db_labor)
{
echo( "<P>Unable to connect to the database server at this
time.</P>" );
exit();
}
mysql_select_db("Labor_Log", $db_labor);
Tim Legg