in reply to how to use DBI connect to >1 database

To my understanding, the reason Perl's DBI must connect to a database, not just to a particular SQL host irrespective of a database, is because SQL privileges are granted on a database-specific level, and one must provide the appropriate credentials to connect to that database on the SQL server. In your case, the same credential allows you access to the second database within that same server, so you are able to include DB2 in the query for DB1.

One is left to wonder, however, if the DBI would be able to accept the more complicated scenario involving two separate databases which had separate grant privileges, requiring two separate credentials. In such a case, your scenario might fail--and I can see why this question would come up. Nor do I know what the answer might be in such a case--particularly if one is not sufficiently privileged as to create new database users and grant them access privileges.

Blessings,

~Polyglot~

  • Comment on Re: how to use DBI connect to >1 database

Replies are listed 'Best First'.
Re^2: how to use DBI connect to >1 database
by Polyglot (Chaplain) on Sep 29, 2023 at 00:37 UTC
    In retrospect, perhaps the question is moot, because the query involving two databases already assumes accessing them both through the same privileged user. Even the original query suggested by O'Reilly depends on having accessed the database server through a single user. It would simply be impossible, I think, to initiate a multi-user connection.

    Blessings,

    ~Polyglot~