Jump to content

Multriple Databases Multiple Connections Problem!


a1amattyj

Recommended Posts

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

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 :)

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.