473,569 Members | 2,400 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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_numbe r";
$dbuser1="user1 ";
$dbuser2="user2 ";
$dbpass1="passw ord1";
$dbpass2="passw ord2";
$dbname1="datab ase_I";
$dbname2="datab ase_II";
$db1=mssql_conn ect($dbhost,$db user1,$dbpass1) ;
$db2=mssql_conn ect($dbhost,$db user2,$dbpass2) ;
mssql_select_db ($dbname1,$db1) ;
mssql_select_db ($dbname2,$db2) ;
$query="SELECT. ..";
?>
Nov 11 '08 #1
3 6416
>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_numbe r";
$dbuser1="user1 ";
$dbuser2="user2 ";
$dbpass1="passw ord1";
$dbpass2="passw ord2";
$dbname1="datab ase_I";
$dbname2="datab ase_II";
$db1=mssql_conn ect($dbhost,$db user1,$dbpass1) ;
$db2=mssql_conn ect($dbhost,$db user2,$dbpass2) ;
mssql_select_db ($dbname1,$db1) ;
mssql_select_db ($dbname2,$db2) ;
$query="SELECT. ..";
?>
<?php
$dbhost="server _name\instance_ name,port_numbe r";
$dbuser1="user1 ";

$dbpass1="passw ord1";

$dbname1="datab ase_I";
$dbname2="datab ase_II";
$db1=mssql_conn ect($dbhost,$db user1,$dbpass1) ;

mssql_select_db ($dbname1,$db1) ;

$query="SELECT ... FROM database_I.tabl e1, database_II.tab le2 WHERE ....";
Nov 11 '08 #3

"Gordon Burditt" <go***********@ burditt.orgwrot e in message
news:iO******** *************** *******@posted. internetamerica ...
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
10754
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 TABLE_NAME" I get 4 rows returned. In Enterprise manager:
0
2294
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 (http://www.datadirect.com), the software industry leader in standards-based components for connecting applications to data and an operating unit of Progress...
9
12501
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
8690
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 as a single database giving me one answer on a select statement but the answer fetched from all my defined databases.
0
1134
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 our users could be using any one of them. It seems to me that data access code is not generic in that our stored procedures are all slightly...
1
9753
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 update different tables in the database.. Most of the error I get are I/O requests to the data file (Data file of the production db...
2
3258
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 or Access database as following : It will connect first to the Master database (SQL or Access, connection String of this database should be read...
5
5799
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 same schema so this is a very desirable function. I can configure 2 different connection strings in app,config but I can't figure out how to...
4
4093
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 databases. suppose there is any query for store the same data values in two different databases at the same time. for eg: databases sample1
0
7926
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. ...
0
8138
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that...
0
7983
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the...
0
6287
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then...
1
5514
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes...
0
5223
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert...
1
2117
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1228
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
0
946
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating...

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.