DKY Posted March 22, 2011 Share Posted March 22, 2011 I'm trying to connect to two databases and I'm having problems with the following code. I googled to come up with this but can't figure out the errors I'm getting. $connection="localhost"; $username="user"; $password="password"; $database1="dbone"; $database2="dbtwo"; $db1 = mysql_connect($connection,$username,$password) or die(mysql_error()); $sel1 = mysql_select_db($database1, $db1); $query1 = "SELECT * FROM TBLUSERS"; $result1 = mysql_query($query1, $db1); while($nt1 = mysql_fetch_array($result1, $db1)) { } $db2 = mysql_connect($connection,$username,$password) or die(mysql_error()); $sel2 = mysql_select_db($database2, $db2); $query2 = "SELECT * FROM TBLPD20101101"; $result2 = mysql_query($query2, $db2) or die(mysql_error()); while($nt2 = mysql_fetch_array($result2, $db2)) { } The error I get is Warning: mysql_fetch_array() expects parameter 2 to be long, resource given in C:\xampp\htdocs\HighVisibility\DashBoard2.php on line 13 Warning: mysql_fetch_array() expects parameter 2 to be long, resource given in C:\xampp\htdocs\HighVisibility\DashBoard2.php on line 22 Quote Link to comment https://forums.phpfreaks.com/topic/231343-php-connect-to-two-databases/ Share on other sites More sharing options...
PFMaBiSmAd Posted March 22, 2011 Share Posted March 22, 2011 There's really no way that the code you posted is producing those errors (you don't even have a mysql_fetch_assoc() statement in that code.) Please post the actual code that is producing the errors in order to get help with your code. Quote Link to comment https://forums.phpfreaks.com/topic/231343-php-connect-to-two-databases/#findComment-1190656 Share on other sites More sharing options...
DKY Posted March 22, 2011 Author Share Posted March 22, 2011 I had just noticed I was pulling up the wrong page. I have now fixed the code and the quote in the first post. Sorry about that. Quote Link to comment https://forums.phpfreaks.com/topic/231343-php-connect-to-two-databases/#findComment-1190657 Share on other sites More sharing options...
jcbones Posted March 22, 2011 Share Posted March 22, 2011 The warning tells you what is wrong. You can then look at the manual and it will show you that the second parameter you passed to the function is incorrect. Quote Link to comment https://forums.phpfreaks.com/topic/231343-php-connect-to-two-databases/#findComment-1190665 Share on other sites More sharing options...
DKY Posted March 22, 2011 Author Share Posted March 22, 2011 There are different learning styles (reading, listening, interraction) and I do not learn by reading, instead my learning style is through interraction. So maybe I'm wrong but I understand that to be the point of a forum board, for users who learn through interraction so maybe someone can help me figure out how to pass a correct function? Thanks in advance! Quote Link to comment https://forums.phpfreaks.com/topic/231343-php-connect-to-two-databases/#findComment-1190677 Share on other sites More sharing options...
jcbones Posted March 22, 2011 Share Posted March 22, 2011 I'm trying to point you in a direction that will get your scripts de-bugged, and working in the shortest amount of time possible. The manual simply states that the second argument is optional. Therefore, if you delete the second argument all together, then it will work. Quote Link to comment https://forums.phpfreaks.com/topic/231343-php-connect-to-two-databases/#findComment-1191052 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.