How to retrieve data from another database using PHP, mySQL?


  • is the second database in the same server of the first database?
  • if affirmative: do you access with same credentials?
  • if affirmative: do you have same permissions?

If it is all affirmative then you can access the second database from the same connection to the first database, just prepend the table name with the database, as in the following example:

SELECT `database1`.`table`.`attribute`, `database2`.`table`.`attribute` FROM `database1`.`table`, `database2`.`table`;
Be a part of the DaniWeb community

We're a friendly, industry-focused community of developers, IT pros, digital marketers, and technology enthusiasts meeting, networking, learning, and sharing knowledge.