Member Avatar for jpknoob

I'm having trouble displaying results when i connect to 2 databases. My connection script seems to be working fine and returns no errors;

$connect1 = mysql_connect("localhost","user","pass", true);
$connect2 = mysql_connect("localhost","user","pass", true);

$db_selected = mysql_select_db("database1", $connect1);
$db_selected = mysql_select_db("database2", $connect2);

When i run the queries, however, I'm only managing to get the results from database1 and nothing from database2, not even any errors.My query codes look like;

$query = "select * from tableA";
$result = mysql_query($query, $connect1) or die(mysql_error());

$query = "select * from tableB";
$result = mysql_query($query, $connect2) or die(mysql_error());

Have i gone about this the wrong way? Any help or guidance would be greatly appreciated.

You have done absolutely fine work.
I tried, it is working fine.
You may have some connection problem.
Hope you do fine work like this.
Thanks.
My code

<?php
$connect1 = mysql_connect("localhost","root","rootwdp", true);
$connect2 = mysql_connect("localhost","root","rootwdp", true);

$db_selected = mysql_select_db("student", $connect1);
$db_selected = mysql_select_db("login", $connect2);

$query = "select * from emp";
$result = mysql_query($query, $connect1) or die(mysql_error());

echo mysql_num_rows($result).'<br />';

$query = "select * from members";
$result = mysql_query($query, $connect2) or die(mysql_error());
echo mysql_num_rows($result);
?>
Member Avatar for jpknoob

Thanks for the reply. it seems i left a rogue 'where' statement in the code that wasn't supposed to be there, fixed now and it does indeed work!

Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.