Re: Query 2 MySQL databases in 1 statement




"Snef" <s.franke@xxxxxxxxxx> wrote in message
news:a6ed7$44c7d63e$3ec24175$26825@xxxxxxxxxxxxxxxxx


mootmail-googlegroups@xxxxxxxxx wrote:
noor.rahman@xxxxxxxxx wrote:
I was wondering how it may be possible to query 2 MySQL databases using
one query statement from PHP.

For instance: SELECT database1.tableA.field1 UNION
database2.tableB.field2.

My concern is, when connecting to MySQL (or sending a query), I only
specify 1 database connection resource ID. How does that play out when
connecting to 2 databases?

Thanks.


As I understand it, the database you specify when connecting to mysql
is your default database. For example, if you connect using "db1",
then to query that database, you can just use "SELECT * FROM table1"
which, because of your default database, is equivalent to "SELECT *
FROM db1.table1". You are still able to access other databases by
fully-qualifying the names, so even if "db1" is your default database,
you can still do something like "SELECT * FROM db2.table2".

I assume that they need to be in the same MySQL?

You mean under the same MySQL instance (server). You connect to an instance,
then create databases using that instance, and you can talk to all of those
databases within that instance. The fact that you can designate one of the
databases as the default database does not mean that you can only talk to
that database.

--
Tony Marston
http://www.tonymarston.net
http://www.radicore.org


.



Relevant Pages

  • Re: [PHP] Problem with SELECT statement and reference material wanted..
    ... echo you query and then run it on mysql and see u getting the desired ... I'm having trouble retrieving a selection of my database contents. ... ..I will get all entries from the database, ... required to be named as the column names in the MySQL table, ...
    (php.general)
  • Ordering on Hierarchical Dot Notation
    ... I have a SQL database (MySql) containing a table with a key column which ... The problem is that this column is proving very difficult to sort naturally ... users still want to query the database using the natural representation. ...
    (comp.lang.java.databases)
  • Ordering on Hierarchical Dot Notation
    ... I have a SQL database (MySql) containing a table with a key column which ... The problem is that this column is proving very difficult to sort naturally ... users still want to query the database using the natural representation. ...
    (comp.lang.java.programmer)
  • Re: C client to load binary data to MySQL
    ... to the C standard you're only allowed to compare pointers pointing ... Since one is unlikely to be constructing a query string anywhere even close to 30000 characters long I would say this makes it safe for all implementations without being any harder to read. ... To the OP, if you need further help with the MySQL parts of this, such as the load_image function and connecting to the database, please take it to a suitable group, possibly one with mysql or database in its name, or the MySQL mailing lists. ...
    (comp.lang.c)
  • Re: Request suggestion for query
    ... The first is a request for a suggestion of a SQL query. ... First I suggest you learn some relational database design. ... SELECT SUM(amount) as amount FROM budget WHERE member_id=1 ... Second, LIMIT is a MySQL extension, not standard SQL. ...
    (comp.databases)