我有一个困难的时间连接我的codeanywhere到我的phpmyadmin数据库。我收到这个错误:
“拒绝用户'//username'@'localhost'(使用密码:yes)的sqlstate[hy000][1045]访问”
我的数据库连接看起来像:
<?php
class Database {
private static $dbName = '//database name here' ;
private static $dbHost = 'localhost' ;
private static $dbUsername = '//username here';
private static $dbUserPassword = '//password here';
private static $cont = null;
public function __construct() {
die('Init function is not allowed');
}
public static function connect()
{
// One connection through whole application
if ( null == self::$cont )
{
try
{
self::$cont = new PDO( "mysql:host=".self::$dbHost.";"."dbname=".self::$dbName, self::$dbUsername, self::$dbUserPassword);
}
catch(PDOException $e)
{
die($e->getMessage());
}
}
return self::$cont;
}
public static function disconnect()
{
self::$cont = null;
}
}
?>
我想知道我的localhost和codeawhere是否有问题,或者我只是输入了错误的phpmyadmin。谢谢您。
1条答案
按热度按时间6qfn3psc1#
检查是否有mysql用户“username”@“localhost”和
mysql> select user,host from mysql.user;
命令。如果在主机127.0.0.1中有一个用户名条目,那么在连接参数中将localhost替换为127.0.0.1。或者添加mysql用户'username'@'localhost'并重试。