madrazel wrote:I'm passing $pdo object to a function using global keyword, but in the function I need to check if passed object refers to a correct DB
You don't need to "need to check if passed object refers to a correct DB" file path. You might want to do things like check if an expected table exists with the required columns (use the table_info pragma), but that has nothing to do with the database file path.
EDIT:
madrazel wrote:The solution is to query the database itself:
PRAGMA database_list
No, that will give you one row for the main database, possibly another row for a temporary database, and then more rows for attached databases, if any. The main database will be named main, so it will not provide you with any information concerning the database file. Typically, you would use that pragma to find out what are the attached databases.
EDIT #2:
Oh wait, looks like I am wrong: it is not documented, but the file name is provided, so yes, that will be a solution, if you can get around the problems with file paths that I described earlier.
But, the fact remains: using the database file path is not the right thing to do. What you should be doing, if you really think it necessary, is to check for the table.