Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Error: Access denied for user 'www-data'@'localhost'

Tags:

php

mysql

pdo

I'm running a mysql database (managed through phpmyadmin) on a lubuntu virtual machine, which itself is on a mac 10.6. Everything was working smoothly until earlier, (and I didn't touch any part of the login code!) when I got the following error on my pages:

Erreur : SQLSTATE[28000] [1045] Access denied for user 'www-data'@'localhost' (using password: NO)

I don't understand where this error is coming from as I don't have a user called www-data on phpmyadmin and my files are supposed to be using the root account on the database:

$dbname = 'name';
$dbuser = 'root';
$dbpass = '*****';
$dbhost = 'localhost';
try{
    $linkpdo = new PDO('mysql:host='.$dbhost.';'.$dbname.', '.$dbuser.' , '.$dbpass);
    $linkpdo -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
}
catch (Exception $e) {
    die('Erreur : '.$e->getMessage());
}

After some googling I saw that people modified their config.conf file, but I don't know how or why.

like image 251
Jessica Chambers Avatar asked Apr 19 '16 12:04

Jessica Chambers


1 Answers

Use a double quoted string and the correct parameters for the connect, its easier to build using a double quoted string and $variable expansion.

    $linkpdo = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
    $linkpdo -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
like image 90
RiggsFolly Avatar answered Oct 13 '22 13:10

RiggsFolly