phpmyadmin multiple servers

Posted on 2011-10-01
Last Modified: 2012-05-12
I just installed php_myadmin.  I had a very old copy and the new version is much better.  I want to be able to connect to multiple databases, but I am not sure how.  I have a reseller account, and all account are on the same server.  I connect to each database using localhost, in their own domains (same ip though).  

Also, it doesn't ask for a user name or password, don't I have to supply those?

 * Second server
/* Authentication type */
$cfg['Servers'][$i]['auth_type'] = 'cookie';
/* Server parameters */
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['compress'] = false;
/* Select mysqli if your server has it */
$cfg['Servers'][$i]['extension'] = 'mysql';
$cfg['Servers'][$i]['AllowNoPassword'] = false;
Question by:jackjohnson44
LVL 20

Accepted Solution

Mark Brady earned 500 total points
ID: 36898067
If the user account you are using has the correct privillages and can connect to more than just one database (you need to add the username to each database you want to connect to) then you can simply connect to the first database like this:

// then this line to use that database each time you want to change databases....


Now you are connected and can use the first database. When you want to swap and use another database (provided the username is the same for both databases) use this line....

mysql_select_db(DB_NAME1); // where DB_NAME AND DB_NAME! are the database names you want to work with.

The best way to do this and it is very tidy is to make a file called "constants.php" and inside the file you can setup your entire variable set like database connection details for each database. Here is a sample of what I use. You then include this file into every php script that you need to connect to your databases.. Here is the file..

/* constants.php */
/* Turn all error warnings and displays off for security and on for debugging */
error_reporting(0);  // Uncomment this line and comment out next line before making this script public
date_default_timezone_set('Antarctica/McMurdo'); // use your timezone here

define("DB_SERVER", "localhost"); // change this to suit your servername - usually localhost
define("DB_USER", "type_your_username_here"); // your DB username
define("DB_PASS", "your_password_here");
define("DB_NAME", "your_database_name_here");
define("DB_NAME1", "your_database_name1_here");
define("DB_NAME3", "your_database_name2_here");

// Now here is the connection script to connect to DB_NAME
mysql_connect(DB_SERVER, DB_USER, DB_PASS); // connect to localhost or your server
mysql_select_db(DB_NAME); // select the first database to work with

Now by including this saved file with any script, that script is ready to start doing mysql queries. You have already selected the first database (DB_NAME) so do whatever you need to then to select another database somewhere in your php scripts use this line

mysql_select_db(DB_NAME1); // now you are working with the database stored in the variable "DB_NAME1".

Do what you need with database1 then either select the next database the same way or slect the first database again but each database has beed stored in a global variable named "DB_NAME" or "DB_NAME1" or "DB_NAME2".

Just switch between the databases with the line "mysql_select_db("then your database name here");
and you can start performing queries on the new database.

Of course if the username you use to connect to the server only has privillages on one database then you would need to either add that username to the other databases and set privillages for the username, or, close the connection you have each time you want to change, then open a new connection to the server with a different username/password combination. Then select the database that the username is allowed to use.

I hope that is easy enough for you to follow.

Author Comment

ID: 36905173
Thanks, but this is a question about phpmyadmin.  I know how to create a new database connection in code that I write.  phpmyadmin is a mysql management tool with a lot going on.  You can edit the config file and should be able to connect to multiple databases easily.  My question revolves around editing this file.

Featured Post

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Part of the Global Positioning System A geocode ( is the major subset of a GPS coordinate (, the other parts being the altitude and t…
Introduction Since I wrote the original article about Handling Date and Time in PHP and MySQL ( several years ago, it seemed like now was a good time to updat…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
The viewer will learn how to count occurrences of each item in an array.

839 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question