a1amattyj Posted May 11, 2008 Share Posted May 11, 2008 Hello, Okay so, Here is my problem.. (keep it as simple as i can) I currently have 12 mysql databases. Each database contains a large number of forums. Each forum has it's own prefix which is kept the same for the different tables. So like.. forum1_members forum1_posts forum1_other forum2_members forum2_posts forum2_other DB 0 contains the username, database name and password for the other 11 databases in the table smf_dbs Here is my code: <?php //Contains DB connection.. include_once('./mf_functions/functions.inc.php'); //Select Forum Names $smf_forums = mysql_query("SELECT * FROM smf_forums ORDER BY db"); while($row = mysql_fetch_array($smf_forums)){ echo 'Database ID: '; $dbid = $row['db'] ; echo $dbid; echo '<br />'; echo 'Forum Name: '; echo $row['name']; echo "."; $id = $row['domainid']; $domains = mysql_query("SELECT name AS domain FROM smf_domains WHERE id = '$id'"); $res = mysql_fetch_array($domains); $res2 = $res['domain']; echo $res2; $databases = mysql_query("SELECT * FROM smf_dbs WHERE id = '$dbid'"); $row = mysql_fetch_array($databases); $conn = mysql_connect($row['host'], $row['user'], $row['password']) or die(mysql_error()); echo "<br />Connected to MySQL<br />"; mysql_select_db($row['name']) or die(mysql_error()); echo "Connected to Database"; echo "<br />"; echo '<br />'; } ?> Now, It does DB 0, the main one: Database ID: 0 Forum Name: bluez.edit Connected to MySQL Connected to Database Database ID: 0 Forum Name: generalchat.edit Connected to MySQL Connected to Database and so on.. The error? gets to the 2nd db.. Database ID: 2 Forum Name: bashscape.edit Connected to MySQL Connected to Database Database ID: 2 Forum Name: thcclan. Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/smfnew/public_html/cron12.php on line 19 Warning: mysql_fetch_array(): supplied argument is not a valid MySQL result resource in /home/smfnew/public_html/cron12.php on line 25 Warning: mysql_connect() [function.mysql-connect]: Access denied for user 'smfnew'@'localhost' (using password: NO) in /home/smfnew/public_html/cron12.php on line 27 Table 'smfnew_smfforums2.smf_dbs' doesn't exist I am stumped on how to make it know that smf_dbs is in db 0, not the db it just connected to. Thanks Link to comment https://forums.phpfreaks.com/topic/105131-multriple-databases-multiple-connections-problem/ Share on other sites More sharing options...
a1amattyj Posted May 11, 2008 Author Share Posted May 11, 2008 *bump* Link to comment https://forums.phpfreaks.com/topic/105131-multriple-databases-multiple-connections-problem/#findComment-538329 Share on other sites More sharing options...
tronicsmasta Posted May 11, 2008 Share Posted May 11, 2008 hmmm i see where you get your error in this code: $databases = mysql_query("SELECT * FROM smf_dbs WHERE id = '$dbid'"); $row = mysql_fetch_array($databases); $conn = mysql_connect($row['host'], $row['user'], $row['password']) or die(mysql_error()); echo "<br />Connected to MySQL<br />"; this is outputting that you are not using a password so $row['password'] is not returning anything... you should double check that $row is outputing the array you want it to print_r($row); then continue to find your issue Link to comment https://forums.phpfreaks.com/topic/105131-multriple-databases-multiple-connections-problem/#findComment-538334 Share on other sites More sharing options...
a1amattyj Posted May 11, 2008 Author Share Posted May 11, 2008 All passwords and fields are correct - still same error Thanks Link to comment https://forums.phpfreaks.com/topic/105131-multriple-databases-multiple-connections-problem/#findComment-538559 Share on other sites More sharing options...
a1amattyj Posted May 12, 2008 Author Share Posted May 12, 2008 anybody? Link to comment https://forums.phpfreaks.com/topic/105131-multriple-databases-multiple-connections-problem/#findComment-539373 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.