Web Hosting Talk







View Full Version : Multiple Databases


MikeA
05-30-2003, 11:25 AM
Can anyone tell me why this isn't working?


$connection2 = mysql_connect($mb_db_host, $mb_db_user, $mb_db_password) or die(mysql_error());

if (!mysql_select_db($mb_db_name, $connection2))
{
mysql_close ($connection2);
print".mysql_error()";
die ("stopped at mysql_select_db<p>");
}

$connection1 = mysql_connect($dbservername, $dbusername, $dbpassword) or die(mysql_error());;

if (!mysql_select_db($dbname, $connection1))
{
mysql_close ($connection1);
print".mysql_error()";
die ("stopped at mysql_select_db<p>");
}


$query = "SELECT *
FROM client_info";

$result = mysql_query($query, $connection2) or die(mysql_error());

while ($items = mysql_fetch_array($result))
{
$client_billing_id = stripslashes($items["client_id"]);


There is more code, but the jist of this is that the information it's grabbing is from whatever the last database that was opened, the $connectionX doesn't seem to make a difference.

ilyash
05-30-2003, 05:52 PM
finish your while loop at the end

plugged
05-30-2003, 08:52 PM
<?php

$connection2 = mysql_connect($mb_db_host, $mb_db_user, $mb_db_password) or die(mysql_error());

// learn to use the 'or' operator
mysql_select_db($mb_db_name,$connection2) or die("mysql error, could not select db (1): " . mysql_error());

// watch the extra semicolon at the end
$connection1 = mysql_connect($dbservername, $dbusername, $dbpassword) or die(mysql_error());

mysql_select_db($dbname,$connection1) or die("mysql error, could not select db (2): " . mysql_error());
// read above

$query = "SELECT * FROM client_info";

$result = mysql_query($query, $connection2) or die(mysql_error());

// watch what type of array you're returning...
// you want an associative array (key => value)
while ($items = mysql_fetch_assoc($result)) {
$client_billing_id = stripslashes($items["client_id"]);
// ....
}

?>

plugged
05-30-2003, 08:53 PM
sorry for the tables distortion

MikeA
06-02-2003, 05:27 PM
Plugged, I tried your way before I posted the message. I ended up getting it to work, I just did it in a different manner.

Why did you say:

// watch what type of array you're returning...
// you want an associative array (key => value)

??

They array I was doing was fine, so I didn't understand why you suggested an associative one.