I have 30 individual databases which I want to consolidate to a single database for data analysis. I have defined two database connections for PHP to use,
$db_source = mysql_connect(stuff);
$db_sink = mysql_connect(stuff);
I can then tell each connection to use a different database:
mysql_select_db('consolidated',$db_sink);
mysql_select_db('ind_01',$db_source);
but when I use mysql_query with select and insert statements, they fail unless I specifically re-select each database, even though I am supposudly using different connections. Am I missing something? Why doesn't this work better?
eg.
$source_records = mysql_query($query,$db_source)
$num_records = mysql_num_records($source_records);
for($i=0;$i<$num_records;$i++)
{
$record = mysql_fetch_row($source_records);
$insert = mysql_query($insert,$db_sink);
}
NB: $insert = "Insert into mytable values(the appropriate values)";
$query = "Select * from mytable";
the above will not work unless I reselect the $db_sink database after every time I use (select from) the $db_source database. I just don't get it.
Thanks for any insight,
Paul