skip to Main Content

I need to create a query which connects to different databases with different users. Every database has its own user.

Can I achieve this with PHPMyAdmin?

2

Answers


  1. If you need different users to connect, then this is not possible at all within MySQL because a query runs in the name of a single user.

    You need to have a single user that can access all databases and all the databases must be within the same MySQL server. Then you can write queries affecting tables from multiple databases, just refer to the tables using database_name.table_name convention.

    Login or Signup to reply.
  2. if what you need is accessing two db in a single query, I’m not really sure if it is possible.

    However, you can still have a workaround for that,
    Create two connections for querying data, then do data processing in PHP.

    $this->firstDb = new Database($dbConn['db_host'], $dbConn['db_name'], $dbConn['db_username'], $dbConn['db_password']);
    $this->secondDb = new Database($dbConn['db_host'], $dbConn['db_name'], $dbConn['db_username'], $dbConn['db_password']);
    
    
    $firstDbData = $this->firstDB->query('SELECT SOME DATA HERE');
    $secondDbData = $this->secondDb->query('SELECT SOME DATA HERE');
    
    $this->processData($firstDbData, $secondDbData);
    
    Login or Signup to reply.
Please signup or login to give your own answer.
Back To Top
Search