创建两个数据库并匹配

I'm a begginer in php. Currently i'm doing a project involved two database connection. In which, one is student.db and one is library.db. After the user login (student.db), they must be displayed with the books (library.db) that matches with the subject that they are taking current semester. I'm confused on how to do the matching process.

I tried linking using

SELECT library.codes, library.book_name, library.link
FROM library_db.library library
LEFT JOIN registrar_db.student student
    ON library.codes = student.subject1
WHERE student.subject1 IS NOT NULL

it does not display anything. Can anyone help me with that?