cannondale;11033553 wrote:
I believe one connection would allow access to both databases ONLY if the user credentials were identical. Correct?
Not necessarily. One connection would allow access to both databases if the specified user is granted such access from the connecting address. Do note that you may very well have to distinct users, where each of the users has access to "both databases" while neither user can access any table that the other user can access. That is, user1 might access db1.table1 and db2.table1, while user2 can access db1.table2 and db2.table2. Or they may have access to the exact same tables, except that user1 has SELECT access only while user2 has UPDATE access only.
Moreover, user1 connecting from localhost may have access to db1, while the same username connecting from web-server-1 has access to db2.
cannondale;11033553 wrote:
Instead, it requires the table name in the second DB to be fully qualified with the DB name.
You may very well have a connection without having selected a database. While "database" is often used for everything, it may be clearer if you state that the connection is made to the server after which you must specify which schema to use. One server or RDBMS may contain several schemas (or databases).
However, looking at the code you presented initially, it wont' work due to errors. Start by correcting those so that you may actually run the code and inspect what happens.
Also note that you can specify schema in several different ways.
1. when creating the connection - sets default schema to be used
2. [man]mysqli::select_db[/man] - sets default schema to be used
3 The SQL statement "use", as in: use schema_name; Although considering that there is a specific API call for this, using select_db is most likely better - sets default schema to be used
4. qualifying table identifiers with schema name, as in: SELECT stuff FROM schema_name.table_name - has to be made every time a non-default schema is used