Jump to content

Can't connect to MySQL database using XAMPP


wtmh144

Recommended Posts

Just as the title says. I searched and couldn't find anything. :\

 

I didn't know exactly where this should go. So I posted it on a MySQL forum too.

 

So basically I can not connect to the database. I'm pretty sure it's a clear case of directory issues. But for some reason I can't wrap my brain around it.

 

My http://localhost goes to: C:\xampp\htdocs

 

My website root folder is: C:\xampp\htdocs\test

 

The 'sitename' database is at: C:\xampp\mysql\data\sitename

 

<?php

// Set the database access information as constants.
DEFINE ('DB_USER', 'jeff');          \\Known to be correct.
DEFINE ('DB_PASSWORD', 'jeff');  \\Known to be correct.
DEFINE ('DB_HOST', 'localhost');  \\What should this be?
DEFINE ('DB_NAME', 'sitename');  \\What should this be?

// Make the connnection.
$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error() );

// Select the database.
@mysql_select_db (DB_NAME) OR die ('Could not select the database: ' . mysql_error() );
?>

Yes that is fine. You use localhost as the hostname when mysql is installed on the same server the website is hosted off. For selecting a database your just specify the name of the database, not the path of where the database is stored - that is all handled by mysql.

Adding to what wildteen88 said....

 

Open phpMyAdmin (http://localhost/phpmyadmin/index.php) and in the box for "Create new database", type in the name of the database you want to create.  You will then have to add the fields unless your program is set up to do that for you.

 

 

As previously mentioned, the user and password are known to be 'jeff'. Please let me know if Im coding the $cfg wrong.

 

$cfg['Servers'][$i]['user']  = 'jeff';
$cfg['Servers'][$i]['password']  = 'jeff';

 

The database 'sitename' exists in PhpMyAdmin with data already populated. (I figured this would have been obvious.) ;)

 

 

The code currently stands as:

 

<?php

// Set the database access information as constants.
DEFINE ('DB_USER', 'jeff');             //Yes, I have tried 'root'
DEFINE ('DB_PASSWORD', 'jeff');
DEFINE ('DB_HOST', 'localhost');
DEFINE ('DB_NAME', 'sitename');

// Make the connnection.
$dbc = @mysql_connect (DB_HOST, DB_USER, DB_PASSWORD) OR die ('Could not connect to MySQL: ' . mysql_error() );

// Select the database.
@mysql_select_db (DB_NAME) OR die ('Could not select the database: ' . mysql_error() );
?>

 

...And is not connecting.

Still seeing: "Could not connect to MySQL: Unknown MySQL server host '../localhost' (11001)"

 

Help?  ;D

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.