How to execute dependent multiple SQL queries from multiple databases via same PHP web page?
You shouldn't need two connections for this as the databases in your code are on the same MySQL instance and the DB user apparently has grants to use both.

All you have to do is prefix your table with the database name in the SQL statements, as you have already done. You can use the same connection for both. (It doesn't matter which database is specified in the connection parameters, I suspect this parameter can even be empty.)