Welcome to WebmasterWorld Guest from 188.8.131.52
I'm looking for a solution on howto join multiple tables across databases.
This bit of code does not work.. yet..
a.ID = b.ID
$SqlSelectResult = mysql_query($SqlSelectQuery, $db1);
$SqlSelectResult2 = mysql_query($SqlSelectQuery, $db2);
Is it possible to join tables across multiple databases?
From the php annotated manual:
resource mysql_query ( string $query [, resource $link_identifier] )
mysql_query() sends an unique query (multiple queries are not supported) to the currently active database on the server that's associated with the specified link_identifier.
It is a server link and you can query any databases's on the server with that one link
I think I may be missing something here.
I'm calling two resource links that connect to two databases.
How do I merge these resource links and get mysql_query() to use them?
// Resource link, db1
$db1 = mysql_connect ("localhost", "user1", "password1") or die("Could not connect.");
// Resource link, db2
$db2 = mysql_connect ("localhost", "user2", "password2") or die("Could not connect.");
The only way i have found is to use GRANT option to change priviledges between the two users of the two databases (assuming these are different users).
I grant one user access to both databases, and then run my queries using that user
You need to use the database prefix:
$query = "SELECT a.field1, b.field1 FROM database1.table1 as a, database2.table1 as b WHERE database1.table1.field2='' AND ..... ";
Hope this makes sence.
And i hope for a better solution to exist (its frustrating to change priviledges constantly)