473,287 Members | 3,228 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,287 software developers and data experts.

Select data from two different databases

I have 2 databases (with different user names and different
passwords), and I need to join column_1 from table_A (on first
database: database_I) on column_2 from table_B (on second database:
database_II).
How query should likes? I want to do this in php - where should I
specify different user names and diffrent passwords for databases?
<?php
$dbhost="server_name\instance_name,port_number";
$dbuser1="user1";
$dbuser2="user2";
$dbpass1="password1";
$dbpass2="password2";
$dbname1="database_I";
$dbname2="database_II";
$db1=mssql_connect($dbhost,$dbuser1,$dbpass1);
$db2=mssql_connect($dbhost,$dbuser2,$dbpass2);
mssql_select_db($dbname1,$db1);
mssql_select_db($dbname2,$db2);
$query="SELECT...";
?>
Nov 11 '08 #1
3 6401
>I have 2 databases (with different user names and different
>passwords), and I need to join column_1 from table_A (on first
database: database_I) on column_2 from table_B (on second database:
database_II).
It's fairly easy to access more than one database in PHP - just
open a connection to more than one, and use the resource for the
appropriate connection for each query. That, however, doesn't imply
being able to use tables from both in the same query.
>How query should likes? I want to do this in php - where should I
specify different user names and diffrent passwords for databases?
A query must be directed to a particular database. If that database
is capable of doing a join with another database (some cannot), you
have to use whatever syntax is needed to do that. This probably
requires giving one database the login parameters for the OTHER
database.

For example, if you were using (sufficiently recent) MySQL, you
could create a Federated table on one server which references the
data stored on the other server, and then run the query to join the
local and the Federated table on that server. (You have to be sure
that the Federated storage engine is enabled).

I don't know how you do it in MSSQL, or if it is possible.

Nov 11 '08 #2
krzys schreef:
I have 2 databases (with different user names and different
passwords), and I need to join column_1 from table_A (on first
database: database_I) on column_2 from table_B (on second database:
database_II).
How query should likes? I want to do this in php - where should I
specify different user names and diffrent passwords for databases?
<?php
$dbhost="server_name\instance_name,port_number";
$dbuser1="user1";
$dbuser2="user2";
$dbpass1="password1";
$dbpass2="password2";
$dbname1="database_I";
$dbname2="database_II";
$db1=mssql_connect($dbhost,$dbuser1,$dbpass1);
$db2=mssql_connect($dbhost,$dbuser2,$dbpass2);
mssql_select_db($dbname1,$db1);
mssql_select_db($dbname2,$db2);
$query="SELECT...";
?>
<?php
$dbhost="server_name\instance_name,port_number";
$dbuser1="user1";

$dbpass1="password1";

$dbname1="database_I";
$dbname2="database_II";
$db1=mssql_connect($dbhost,$dbuser1,$dbpass1);

mssql_select_db($dbname1,$db1);

$query="SELECT ... FROM database_I.table1, database_II.table2 WHERE ....";
Nov 11 '08 #3

"Gordon Burditt" <go***********@burditt.orgwrote in message
news:iO******************************@posted.inter netamerica...
I have 2 databases (with different user names and different
passwords), and I need to join column_1 from table_A (on first
database: database_I) on column_2 from table_B (on second database:
database_II).

It's fairly easy to access more than one database in PHP - just
open a connection to more than one, and use the resource for the
appropriate connection for each query. That, however, doesn't imply
being able to use tables from both in the same query.
>>How query should likes? I want to do this in php - where should I
specify different user names and diffrent passwords for databases?

A query must be directed to a particular database. If that database
is capable of doing a join with another database (some cannot), you
have to use whatever syntax is needed to do that. This probably
requires giving one database the login parameters for the OTHER
database.

For example, if you were using (sufficiently recent) MySQL, you
could create a Federated table on one server which references the
data stored on the other server, and then run the query to join the
local and the Federated table on that server. (You have to be sure
that the Federated storage engine is enabled).

I don't know how you do it in MSSQL, or if it is possible.

Yes, you can do it with MSSQL...that was exploited a few years back with the
advent of MSDE. The default install used 'admin' with a blank password...and
users were too stupid or lazy to change it. So, remote into a MSSQL port as
admin, enumerate all MSSQL servers on the network, replicate yourself to
them, do your harm. I digress, yes, it is easily done in MSSQL. I'd only
create a view of the remote/secondary table(s) involved in the other server.
From there, connect to the one and pull your view into a query of it's
related, local table.
Nov 11 '08 #4

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Rowland Hills | last post by:
I have a table which is returning inconsistent results when I query it! In query analyzer: If I do "SELECT * FROM TABLE_NAME" I get no rows returned. If I do "SELECT COL1, COL2 FROM...
0
by: Stylus Studio | last post by:
DataDirect XQuery(TM) is the First Embeddable Component for XQuery That is Modeled after the XQuery API for Java(TM) (XQJ) BEDFORD, Mass.--Sept. 20, 2005--DataDirect Technologies...
9
by: gopi | last post by:
when installing db2, it only asks for installation directory and does not ask where it is going to store data files. how can i change the default directory after installation.
3
by: rallykarro | last post by:
Hi, How do I at the best way perform select statements over multiple databases? I have a couple of databases containing the same table definitions with diffrent data. Now I want them to act...
0
by: D Lester | last post by:
I have recently create membership providers for several diferrent databases which has led me down this path of thought. I need to implement a data access layer for several different databases as...
1
by: Query Builder | last post by:
I have one of our production Accounting Databases starting from 2 GB now grown into a 20 GB Database over the period of a few years... I have been getting timeouts when transactions are trying to...
2
by: Orit | last post by:
Hello . Please find below my questions - I hope some of the ASP.NET experts of this forum will answer to those beginner's questions : My Web site should be able to work with either SQL Server...
5
by: Edwin Smith | last post by:
Hello: I'm using VS2005 with an ODBC database. I am trying to add a Dialog to an existing Database application to allow the user to select the database. We have 2 different databases with the...
4
by: sganeshsvk | last post by:
sir, i want to store the same data values in two different databases at that same time in mysql using php programming. suppose any one databases data will lose then we use the other...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 7 Feb 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:30 (7.30PM). In this month's session, the creator of the excellent VBE...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: Aftab Ahmad | last post by:
Hello Experts! I have written a code in MS Access for a cmd called "WhatsApp Message" to open WhatsApp using that very code but the problem is that it gives a popup message everytime I clicked on...
0
by: Aftab Ahmad | last post by:
So, I have written a code for a cmd called "Send WhatsApp Message" to open and send WhatsApp messaage. The code is given below. Dim IE As Object Set IE =...
0
by: marcoviolo | last post by:
Dear all, I would like to implement on my worksheet an vlookup dynamic , that consider a change of pivot excel via win32com, from an external excel (without open it) and save the new file into a...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.