0

I have my XAMPP running up apache and mysql are running and try to a simple mysql_connect

mysql_connect('localhost', 'root', 'test123');

but the mysql_error() comes back with

Failed to connect to MySQL host. Access denied for user 'root'@'localhost' (using password: YES)

So, I open up config.inc.php inside myphpadmin and verified the credentials are correct.

  /* Authentication type */
  $cfg['Servers'][$i]['auth_type'] = 'config';
 /* Server parameters */
$cfg['Servers'][$i]['host'] = 'localhost';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'test123';
$cfg['Servers'][$i]['connect_type'] = 'socket'; 
$cfg['Servers'][$i]['compress'] = false;
$cfg['Servers'][$i]['AllowNoPassword'] = true;
 /* Select mysqli if your server has it */
$cfg['Servers'][$i]['extension'] = 'mysql';

The only thing I am not sure is the $cfg['Servers'][$i] thing. What's this $i? Are there multiple instances of Servers?

lilzz
  • 5,243
  • 14
  • 59
  • 87
  • 1
    Are you trying to connect to MySQL from your own script, or from PhpMyAdmin? – deceze Feb 21 '12 at 01:45
  • Maybe this can answer your question. http://stackoverflow.com/questions/6445917/connect-failed-access-denied-for-user-rootlocalhost-using-password-yes – Leysam Rosario Feb 21 '12 at 01:48
  • i had the same problem in the past try to go to this conversation [http://stackoverflow.com/questions/6445917/connect-failed-access-denied-for-user-rootlocalhost-using-password-yes](http://stackoverflow.com/questions/6445917/connect-failed-access-denied-for-user-rootlocalhost-using-password-yes) – Bert Feb 21 '12 at 01:51
  • OK, I figure it out. the moral of story is don't use root, and generate a username and with password and it worked. – lilzz Feb 21 '12 at 03:34

1 Answers1

0

try this one:

$hostname_koneksi = "localhost";
$database_koneksi = "your_database";
$username_koneksi = "your_username";
$password_koneksi = "your_password";
$koneksi = mysql_pconnect($hostname_koneksi, $username_koneksi, $password_koneksi) or trigger_error(mysql_error(),E_USER_ERROR); 
mysql_select_db($database_koneksi) or die("Can't open the database!");

Edit: you create this script on a file, and use include function to the file that you want to use this connection..

this is my own setting on config.inc.php

/* 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 mysql if your server does not have mysqli */
$cfg['Servers'][$i]['extension'] = 'mysqli';
$cfg['Servers'][$i]['AllowNoPassword'] = true;
blankon91
  • 521
  • 3
  • 15
  • 39
  • The process of the code above is similar to this one sir. Maybe the problem is similar to this one http://stackoverflow.com/questions/6445917/connect-failed-access-denied-for-user-rootlocalhost-using-password-yes – Leysam Rosario Feb 21 '12 at 01:51
  • so, the problem is on the config.inc.php? – blankon91 Feb 21 '12 at 01:55