Answer the question
In order to leave comments, you need to log in
How to run cross-database SQL query PHP/PDO?
Good afternoon.
In the internet, I found a hint of an interbase query, ala
SELECT t1.*, t2.* FROM database1.table1 AS t1 database2.table1 AS t2
Answer the question
In order to leave comments, you need to log in
PDO has a connection to the DBMS, and there can be several databases in one DBMS.
I explain:
It's not "PDO has a connection", but the database user has access to .
If the user specified during the connection has access to a certain database, then we can execute queries to it.
From this we can conclude: If the user specified when connecting has access to both databases, then such a query is not a perversion, but completely standard SQL.
If there is access to only one database, then the request will fail. Again, not because of its non-standard, but because of the banal reason for the lack of access.
And whether we connect through PDO, or through the console - it doesn't matter.
What MySQL calls a "database" is not exactly a database in the sense of other DBMSs, but more than schemas. This allows you to easily query between them, just like in other DBMS you can do it between schemas. And the database in the understanding of the databases of other DBMSs in MySQL is always one, so the connection is, as it were, always connected to it.
The whole trouble lies in the fact that, as a rule, developers test working with databases on a local mysql server, where he has access to the entire server structure. And when we put scripts on hosting, there is another security structure. Many hosters add a user to the database (not to the DBMS) with a prefix of the database name like username_dbname. This is due to the fact that host admins, as a rule, do not bother to deeply configure the DBMS, but are limited to the default capabilities of phpMyAdmin. One user per database. As a result, the developer finds himself in such a sandbox with restrictions. Therefore, before you buy hosting, make sure that you have all the necessary features on the hosting.
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question