Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

phpmyadmin multiple servers

Posted on 2011-10-01
2
Medium Priority
?
345 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 2000 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

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

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

There are times when I have encountered the need to decompress a response from a PHP request. This is how it's done, but you must have control of the request and you can set the Accept-Encoding header.
In this blog post, we’ll look at how using thread_statistics can cause high memory usage.
The viewer will learn how to create a basic form using some HTML5 and PHP for later processing. Set up your basic HTML file. Open your form tag and set the method and action attributes.: (CODE) Set up your first few inputs one for the name and …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…

722 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