The issue is that PHPStorm does not seem to parse the table name as a variable.
$dbTo.tableName and associated column names are not correctly identified.
If in the above example is the variable $dbTo replace with the correct table name then all is good
$database2 = 'database2';
.....
LEFT JOIN ".$database2.".users table2 on table1.id = table2.id
.....
.....
LEFT JOIN database2.users table2 on table1.id = table2.id
.....