Hi,
My site was working fine, but I just switched servers/web hosts and now I'm getting the following errors (in blue). The thing is, I don't get the error if I try to run the query loop after just using 'mysql_select_db' once, but if I use it again to select a different database and then run the query loop, I start getting the error.
mysql_select_db ("database1", $mysql_con);
$mysql_query = mysql_query ("SELECT ID FROM someTable1", $mysql_con);
$someVar1 = 0;
while ($mysql_array = mysql_fetch_array ($mysql_query))
{
$someVar1 ++;
}
////// The above code gives me no error. But If I then try to select a different database and run a loop in the same way (in the same file), I start getting the below error...
mysql_select_db ("database2", $mysql_con);
$mysql_query = mysql_query ("SELECT ID FROM someTable2", $mysql_con);
$someVar2 = 0;
while ($mysql_array = mysql_fetch_array ($mysql_query))
{
$someVar2 ++;
}
Warning: mysql_fetch_array() expects parameter 1 to be resource, boolean given in /home/snubby5/public_html/coozymcmillan.com/view.php on line 86
So I looked it up and somewhere it told me to add some extra code to handle errors better:
if ($mysql_query === FALSE) {
die (mysql_error ()); // TODO: better error handling
}
But when I do that, I get a different error:
Table 'database1.someTable2' doesn't exist
It doesn't seem to recognize that I switched databases, and it says 'database1.someTable2' doesn't exist (because it doesn't), when really it should be checking for 'database2.someTable2' (which exists).
So to reiterate, I can run the query loop fine after selecting database1, but after that if I select database2, it either gives me the first error, or If I add the 'die' code it gives me the second error.
Thanks much!
PS: I can get it working if I put everything into one database, but I have multiple websites (which sometimes need to call eachothers' databases) and it would be a huge hassle to cram them all into one database unless I have to.