StevieCritoph Posted March 1, 2012 Share Posted March 1, 2012 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. Link to comment https://forums.phpfreaks.com/topic/258022-table-doesnt-exist-error-because-mysql_select_db-only-works-once/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 1, 2012 Share Posted March 1, 2012 Debug why the second mysql_select_db statement is failing by changing it to the following - mysql_select_db ("database2", $mysql_con) or die("Select db database2 failed due to: " . mysql_error($mysql_con)); Link to comment https://forums.phpfreaks.com/topic/258022-table-doesnt-exist-error-because-mysql_select_db-only-works-once/#findComment-1322581 Share on other sites More sharing options...
StevieCritoph Posted March 1, 2012 Author Share Posted March 1, 2012 Debug why the second mysql_select_db statement is failing by changing it to the following - mysql_select_db ("database2", $mysql_con) or die("Select db database2 failed due to: " . mysql_error($mysql_con)); Thank you so much, it works now. Turns out I forgot to add that user to all the databases, I just added it to the first one. I'll be sure to use 'die' to help debug things from now on. Link to comment https://forums.phpfreaks.com/topic/258022-table-doesnt-exist-error-because-mysql_select_db-only-works-once/#findComment-1322585 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.