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() );
?>

Link to comment
Share on other sites

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.

Link to comment
Share on other sites

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

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • 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.