PHPMyAdmin - connect to MySQL

Hi,

I am learning how PHPMyAdmin works, but am struggling a bit.  I managed to get Xampp installed which gives me PHPMyAdmin and Apache server.  Now I need to connect to MySQL with the constants given below.  Can anyone give me instructions on how to do this?
<?php
// MySQL server
define('DB_HOST', '');

// Database name
define('DB_NAME', '');

// MySQL username
define('DB_USER', '');

// MySQL password
define('DB_PASS', '');
?>

Open in new window

NerishaBAsked:
Who is Participating?

[Product update] Infrastructure Analysis Tool is now available with Business Accounts.Learn More

x
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Dave BaldwinFixer of ProblemsCommented:
Here is the mysql-connect page http://us3.php.net/manual/en/function.mysql-connect.php .  After you complete the definitions for the constants, you use them in place of the literals frequently used.  Examples of both below.
Literals
<?php
$link = mysql_connect('localhost', 'mysql_user', 'mysql_password');
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>

Constants
<?php
$link = mysql_connect(DB_HOST, DB_USER, DB_PASS);
if (!$link) {
    die('Could not connect: ' . mysql_error());
}
echo 'Connected successfully';
mysql_close($link);
?>

Open in new window

0
Dave BaldwinFixer of ProblemsCommented:
After thinking for a second, I'll add this.  You do have to create thru phpmyadmin a database of your own with tables for your data and a user with permissions to use that database.  MySQL connections are based on the user permissions.  If you don't have a user that is allowed to connect to the server and database, your connection won't work.  http://dev.mysql.com/doc/refman/5.1/en/adding-users.html

Note that users can have 'localhost', 'anyhost', or a specific host connection.  It is common to create the same user and password with both 'localhost' and 'anyhost' permissions.  It is Not recommended to use root to access your database.  If you were to put your database on shared hosting somewhere, you would not be allowed to use 'root' at all.
<?php
// MySQL server
define('DB_HOST', 'localhost');

// Database name
define('DB_NAME', 'yourDB');

// MySQL username
define('DB_USER', 'yourUser');

// MySQL password
define('DB_PASS', 'yourPWD');
?>

Open in new window

0
ropennerCommented:
This should give enough hints to figure it out:

Once Xampp is installed you should be able to use your web browser (IE, firefox, safari, chrome) to view a website located at http://localhost/phpmyadmin.

http://localhost/phpmyadmin

or for example if you used another port as the default apache port

http://localhost:81/phpmyadmin/

From there you can setup your databases: create new, add tables etc.
______________________________________
for WAMP there is a config file that gives what all the local settings are for host and port

    C:\wamp\apps\phpmyadmin3.3.9\config.inc.php

it looks like this

<?php

/* Servers configuration */
$i = 0;

/* Server: localhost [1] */
$i++;
$cfg['Servers'][$i]['verbose'] = 'localhost';
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['port'] = '';
$cfg['Servers'][$i]['socket'] = '';
$cfg['Servers'][$i]['connect_type'] = 'tcp';
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = '????????'; // there will be an actual password in here not question marks
$cfg['Servers'][$i]['AllowNoPassword'] = false;
________________________________________

In PHP now to access those databases and tables

<?php
// fill in these five with your settings
$host='';
$user='';
$password='';
$databasename='';
$table='';


$database = new mysqli();

$database->connect($host, $user,$password,$databasename);
$sql = "SELECT * FROM $table";
$statement_handle = $database->query($sql);
while ($value = $statement_handle->fetch_row()) {
      for ($i=0; $i < count($value); $i++) {

            print "\t{$value[$i]}";

      }
}

$database->close();
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Lukasz ChmielewskiCommented:
Usually - if you did nothing, the setup would be like this:
host: localhost
user: root
password: (empty)
0
NerishaBAuthor Commented:
Thanks alot
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
MySQL Server

From novice to tech pro — start learning today.