Solved

phpmyadmin multiple servers

Posted on 2011-10-01
2
337 Views
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
 */
$i++;
/* 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;
0
Comment
Question by:jackjohnson44
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
2 Comments
 
LVL 20

Accepted Solution

by:
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:

mysql_connect($SERVER_NAME, DB_USER, DB_PASSWORD);
// then this line to use that database each time you want to change databases....

mysql_select_db(DB_NAME);

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 */
<?php
/* Turn all error warnings and displays off for security and on for debugging */
ini_set("display_errors","off");
error_reporting(0);  // Uncomment this line and comment out next line before making this script public
//error_reporting(E_ALL);
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.
0
 

Author Comment

by:jackjohnson44
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.
0

Featured Post

Will your db performance match your db growth?

In Percona’s white paper “Performance at Scale: Keeping Your Database on Its Toes,” we take a high-level approach to what you need to think about when planning for database scalability.

Question has a verified solution.

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

3 proven steps to speed up Magento powered sites. The article focus is on optimizing time to first byte (TTFB), full page caching and configuring server for optimal performance.
Many old projects have bad code, but the budget doesn't exist to rewrite the codebase. You can update this code to be safer by introducing contemporary input validation, sanitation, and safer database queries.
The viewer will learn how to dynamically set the form action using jQuery.
The viewer will learn how to look for a specific file type in a local or remote server directory using PHP.

623 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