Jump to content

Recommended Posts

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

Link to comment
https://forums.phpfreaks.com/topic/231343-php-connect-to-two-databases/
Share on other sites

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.

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!

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.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.