You can only use one connection for a particular query, and it has to be provided as the first argument to mysqli_query()
. If you want to access both databases in the same query, you need to use a connection with a username that has access to both databases. You don't need to use a different connection just because you're accessing different databases -- the database in the connection is just the initial default, but you can change it with mysqli_select_db()
, and override it temporarily in a query by using the database prefix on the table name.
You can't refer to db1.*
in a query, you have to specify the table name db1.videos.*
So if username1
has permission to read both db1
and db2
, you can do:
$sql = mysqli_query($link1, "SELECT db1.videos.* FROM db1.videos WHERE db1.VID NOT IN (SELECT VID FROM db2.videos)");