Tutorial :Access 2nd MySQL db in PHP without mysql_select_db()



Question:

If I select a db db1 with mysql_select_db() is it possible to access another db db2 in a query? I am looking for something like SELECT * FROMdb2.sometableWHERE 1


Solution:1

That syntax should work perfectly fine. If you want to access a table from another database the syntax is:

SELECT * FROM DatabaseName.TableName WHERE ....  

However, this only works if both databases are on the same instance of MySQL.


Solution:2

I think yes - have you tried it? and do you have access privileges to the 2nd db?


Solution:3

its possible just reference the db name in your query like select * from db.table


Note:If u also have question or solution just comment us below or mail us on toontricks1994@gmail.com
Previous
Next Post »