Jump to content

php connect to two databases


DKY

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
Share on other sites

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!

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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.