0

I know this question has been asked countless times but I went through all of the solution proposed and none could solve my problem so far...

So I can access phpmyadmin, I've tried with & without a password, and it worked on localhost.

Now my code is online but my database is on localhost (using wamp). I've tried it before and it worked just fine.

When I try to execute the code (it's supposed to send a feedback to the db) I've got this error:

SQLSTATE[28000] [1045] Access denied for user 'root'@'localhost' (using password: YES)

This is how I connect to my db:

try {
$bdd = new PDO('mysql:host=localhost;dbname=lexcelera', 'root', 'password');
}

catch(Exception $e) {
    die('Erreur : ' .$e->getMessage());
}

and this is my config.inc:

/* Authentication type */
$cfg['Servers'][$i]['verbose'] = '';
//$cfg['Servers'][$i]['auth_type'] = 'cookie';
$cfg['Servers'][$i]['auth_type'] = 'config';
$cfg['Servers'][$i]['user'] = 'root';
$cfg['Servers'][$i]['password'] = 'password';
/* 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'] = 'mysql';
$cfg['Servers'][$i]['AllowNoPassword'] = true;

Any solution to my problem? Also I'm using Windows 7 (lot of possible solutions were for Linux unfortunately).

Thanks!

Simon
  • 337
  • 1
  • 3
  • 11
  • 1
    Perhaps your localhost is refusing incoming connections on [port 3306](https://dev.mysql.com/doc/refman/5.5/en/connecting.html)? Check your firewall settings. – r3mainer Aug 10 '15 at 10:09
  • I see but I'm not very used to deal with the firewall... how do you check that? – Simon Aug 10 '15 at 10:41
  • Easiest way to check would be to open up a command line console on the remote server and type in `mysql -uroot -p -hxx.xx.xx.xx` (substituting `root` and `xx.xx.xx.xx` for your MySQL user name and the IP address of your local server. – r3mainer Aug 10 '15 at 11:10
  • Just a quick sanity check: The PHP script and MySQL database *are* on different servers, right? And you did remember to replace `localhost` with the IP address of the server hosting your database, right? – r3mainer Aug 10 '15 at 11:13
  • Well I can only access to the distant server via Filezilla so I can't open a command line there, can I? And yes the PHP script and the MySQL are on different servers. The databse is on localhost (wamp). I've tried either 'localhost' and '127.0.0.1' but still the same error. – Simon Aug 10 '15 at 11:49
  • OK, stop right there. `127.0.0.1` and `localhost` both refer to the *local* server where your PHP script is running. You're trying to access a MySQL database that is on a *different* server. You need to replace `localhost` with the IP address of the server hosting your database, and make sure your database server allows external connections on port 3306. – r3mainer Aug 10 '15 at 12:07
  • Well actually it's the other way around: it's MySQL that is on my local machine and the PHP script that is on the distant server :/ – Simon Aug 10 '15 at 12:19
  • I dont understand how you ever got this working with your apparent total lack of understanding of what you say used to work. What has changed since you say you had this working? – RiggsFolly Aug 11 '15 at 00:03
  • Nothing has changed, only a few months passed. That's why I don't understand. Anyway I finally got the access to the server where my php is, created the db there and it's working. Thanks for the help, it's just frustrating that I couldn't make it work the same way it used to... – Simon Aug 11 '15 at 09:32

2 Answers2

0

You copy pasted config is from phpmyadmin I guess. Make sure you can connect to the mysql server at first, maybe from the command line

mysql -u root -p

And than you will be asked for you password, type

password

and press enter.

If it connects than it means that you can access the mysql server with your root account, and the problem is elsewhere.

Than you should check that the database that you are trying to connect (lexcelera) is created.

If it does not work it means you can not access your mysql server, and than it means that the maybe the mysql root user is not configured as in the pasted text (phpmyadmin config).

  • Yes I can connect without problem. Actually I can access it from my computer just fine. It's when I execute the code from my online server that the error appears. – Simon Aug 10 '15 at 10:29
0

if your code is online , on remote server, and your database in on local machine, of course it does not work. localhost point to local machine. when you execute a code on remote machine it's search for local db.

ciro
  • 771
  • 1
  • 8
  • 30
  • I reckon this may be the problem but last year (when I wrote the code) it was working just fine... Is there a free solution to try to connect to a distant server by any chance? – Simon Aug 10 '15 at 10:31
  • you need to allow access from remote to your local machine. try to follow this (http://stackoverflow.com/questions/14779104/how-to-allow-remote-connection-to-mysql). – ciro Aug 10 '15 at 14:31
  • Tried it but nope, still not working... I couldn't find the 'bind-address = 127.0.0.1' to uncomment in my my.ini file he was talking about. Any idea why's that? – Simon Aug 10 '15 at 15:02
  • add it if not found. and set your public ip to it – ciro Aug 10 '15 at 15:06
  • Yep I did it but still not working. I finally got the access to the server where my php is and put my db there. It's working now. It's just strange that I had to do that when sending data to my local db was working jsut fine a few month ago... – Simon Aug 11 '15 at 09:34
  • you need to allow access from remote server for specific user. make sure you firewall firewall is not blocking the connection to mysql.In addition, you need to configure your router for traffic on port 3306, mysql, is redirected to your machine. please if anwer response your question or was useful sign it . – ciro Aug 12 '15 at 09:48