[英]Error: Access denied for user 'www-data'@'localhost'
I'm running a mysql database (managed through phpmyadmin) on a lubuntu virtual machine, which itself is on a mac 10.6. 我在lubuntu虚拟机上运行一个mysql数据库(通过phpmyadmin管理),该虚拟机本身在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) Erreur:SQLSTATE [28000] [1045]访问被拒绝用户'www-data'@'localhost'(使用密码: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: 我不明白这个错误来自哪里,因为我没有在phpmyadmin上有一个名为www-data的用户,我的文件应该使用数据库上的root帐户:
$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. 经过一些谷歌搜索,我看到人们修改了他们的config.conf文件,但我不知道如何或为什么。
Use a double quoted string and the correct parameters for the connect, its easier to build using a double quoted string and $variable
expansion. 使用双引号字符串和连接的正确参数,使用双引号字符串和$variable
扩展更容易构建。
$linkpdo = new PDO("mysql:host=$dbhost;dbname=$dbname", $dbuser, $dbpass);
$linkpdo -> setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
<?php
$dsn = 'mysql:dbname=name;host=localhost';
$user = 'root';
$password = '*****';
try {
$dbh = new PDO($dsn, $user, $password);
} catch (PDOException $e) {
echo 'Connection failed: ' . $e->getMessage();
}
?>
Try this code. 试试这个代码。 Checkout this link for more details http://php.net/manual/en/pdo.connections.php 有关更多详细信息,请访问此链接http://php.net/manual/en/pdo.connections.php
The user and password are separate parameters, http://php.net/manual/en/pdo.connections.php . 用户和密码是单独的参数, http://php.net/manual/en/pdo.connections.php 。
So take out the concatanation here-> .', '.$dbuser.' , '.$dbpass
所以在这里取出连接 - > .', '.$dbuser.' , '.$dbpass
.', '.$dbuser.' , '.$dbpass
. .', '.$dbuser.' , '.$dbpass
。
Connection should be: 连接应该是:
$linkpdo = new PDO('mysql:host='.$dbhost.';dbname='. $dbname, $dbuser, $dbpass);
尝试这个 :
$linkpdo = new PDO('mysql:host='.$dbhost.';dbname='.$dbname , $dbuser, $dbpass);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.