473,659 Members | 3,031 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

multiple database select

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.

Right now the databases are on the same node and I guess it is possible
to do something like:
select * from db1.table1, db2.table1 etc etc. but I really do not want
to modify all my sql statements if another database would comes into
picture or is revoved from the set.

One solution may be to create a view?!
I am using PHP and PEAR DB to access and query my databases.

thanks,

Karolina

Jun 16 '06 #1
3 8692
>How do I at the best way perform select statements over multiple
databases?


If you're talking about different databases handled by the same
server, you can use the databasename.ta blename to refer to tables
outside the current database.

If you're talking about different databases on different servers
potentially on different continents, MySQL has the "Federated" table
type, which allows you to reference a table on another MySQL server
as though it was on this one. Requires at least MySQL 5.0, as I
recall. Don't expect it to be fast. I suspect it fetches the
entire table every time.

Gordon L. Burditt
Jun 16 '06 #2

Gordon Burditt skrev:
How do I at the best way perform select statements over multiple
databases?


If you're talking about different databases handled by the same
server, you can use the databasename.ta blename to refer to tables
outside the current database.

If you're talking about different databases on different servers
potentially on different continents, MySQL has the "Federated" table
type, which allows you to reference a table on another MySQL server
as though it was on this one. Requires at least MySQL 5.0, as I
recall. Don't expect it to be fast. I suspect it fetches the
entire table every time.

Gordon L. Burditt


Hi,

yes, I may use db1.table1, db2.table approach since all my databases
are on the same node at the moment. Still, I want to transparantly be
able to add or remove databases from the set without changing the
specific sql statements refering to the table.

thanks,

karolina

Jun 16 '06 #3
>> >How do I at the best way perform select statements over multiple
>databases?


If you're talking about different databases handled by the same
server, you can use the databasename.ta blename to refer to tables
outside the current database.

If you're talking about different databases on different servers
potentially on different continents, MySQL has the "Federated" table
type, which allows you to reference a table on another MySQL server
as though it was on this one. Requires at least MySQL 5.0, as I
recall. Don't expect it to be fast. I suspect it fetches the
entire table every time.

Gordon L. Burditt


Hi,

yes, I may use db1.table1, db2.table approach since all my databases
are on the same node at the moment. Still, I want to transparantly be
able to add or remove databases from the set without changing the
specific sql statements refering to the table.


You have to tell it where the tables are. You are stuck with that.

Why are all the tables in different databases?

You might be able to refer to the table as $database_of_ta ble1.table1
and let PHP substitute it, but there's got to be a file somewhere
you have to change if you move a table. You could also create a
federated table that points at the actual location of the table,
and re-create it if the actual table moves.

I suppose you could do something like selecting from
INFORMATION_SCH EMA.TABLES to figure out which databases have tables
named 'foo', and then try to figure out which one you should use.
(Requires MySQL 5.0 or greater, doesn't work across multiple servers,
and doesn't really solve the problem anyway).

I don't know of any way to *REMOVE* a table (vs. moving it elsewhere)
without affecting a SQL statement that uses it.

I don't know of any way to *ADD* a table to a SQL statement (presumably
a join) without affecting the SQL statement.

The best way I have found to keep databases out of the SQL is to
put all the tables in the same database, and use an include file
which defines the variables $mysql_server, $mysql_user, $mysql_password ,
and $mysql_db, which I can change for the application without
changing the rest of the page. The application sets the current
database once and never changes it.

If for some reason I can't put all the tables in the same database
I usually end up using two connections (potentially on different
servers) with two sets of these. This approach does not scale very
well, and you can't do joins between tables on different connections.

Gordon L. Burditt
Jun 16 '06 #4

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

Similar topics

3
6106
by: DarthMacgyver | last post by:
Hello, I recently wrote a survey application. Each question is very similar. The first questions gives me a problem when there are multiple people taking the survey (The Database connection Timed out) I am using the Data Access Application Blocks as ASP.NET (using VB.NET) and SQL 2000. In there first question there can be up to 27 answers. So I figured instead of making 27 different trips to the database I woulc just concatenate my...
6
2522
by: Don Leverton | last post by:
Hi All, I've got a situation where I am developing an Access 97 app for a client, and am in the "beta testing" stage. I have split the app up, using the DB splitter, into front-end /back-end for the usual reason ... so I can mess with form/report revisions. Since splitting, I've had issues with re-linking the tables ... as it relates to the completetely different "My Documents" data paths on several different Win98 / Win XP computers.
9
12973
by: jaYPee | last post by:
I have search a lot of thread in google newsgroup and read a lot of articles but still i don't know how to update the dataset that has 3 tables. my 3 tables looks like the 3 tables from northwind database that has an employees, orders, and order details. the following are the 3 tables in my sql database students schyrsem
4
3748
by: Dave Edwards | last post by:
I understand that I can fill a datagrid with multiple queries, but I cannot figure out how to fill a dataset with the same query but run against multiple SQL servers, the query , table structure and username, password etc will be exactly the same for each server, the only thing that will change is the server name. Idealy I would like to get the server names from a seperate dataset so there could be any number of servers, allthough in...
12
1755
by: Peter Proost | last post by:
Hi group, has anyone got any suggestions fot the best way to handle this problem, I've got 3 tables for example table A, B, and C table A looks like name, value table B looks like name, value table C looks like variablename, value, value an example would be
0
1889
by: rich | last post by:
I have a database with 1 to many and the many is a list with multiple selects in a list. When I click on a master record I have as part of my form the select statement for the multiple choice list. I want the list to highlight the multiple chosen values. here is part of the code. $dresscat = specdresscat($dresstypeid); //this is the query to get the values in the detail table $drcatrow = pg_fetch_array($dresscat);// the array for the...
52
6312
by: MP | last post by:
Hi trying to begin to learn database using vb6, ado/adox, mdb format, sql (not using access...just mdb format via ado) i need to group the values of multiple fields - get their possible variations(combination of fields), - then act on each group in some way ...eg ProcessRs (oRs as RecordSet)... the following query will get me the distinct groups
7
5299
by: ozzii | last post by:
Hi I have a HTML form with a multiple select box. The multiple select box is populated from a database. A user can select multiple options form this select box and the infomrtaion is then stored in a database. The user then has the option to edit their saved record. How do i populate this multiple select box from a database with the users selected/saved options highlighted? I can manage to get it to work if the user simply selected one...
2
1930
by: dylanhughes | last post by:
I'm looking for an example of a login system that has multiple fields (2 to be exact) + password. e.g username, company name and password, the user, company and password are checked against a mysql database. I have it working with just the username field but I'm confused on how to go about adding another field. I'm pretty new to PHP so don't beat me up too much for this example code, I borrowed and hacked it together in a very short period...
3
7186
by: DeanL | last post by:
Hi guys, Does anyone know of a way to create multiple tables using information stored in one table? I have a table with 4 columns (TableName, ColumnName, DataType, DataSize) and wanted to know if there is a way to use the information in this table to create the many tables that are listed in the source table instead of creating each table individually? Many thanks for any help you can offer.
0
8337
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8851
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. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8531
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
8628
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 choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6181
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 instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5650
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 into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
1
2754
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
2
1978
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1739
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 effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.