Codeanywhere和Phpmyadmin数据库连接

时间:2018-04-17 05:27:50

标签: php mysql database phpmyadmin codeanywhere

我很难将我的codeanywhere连接到我的phpmyadmin数据库。 我收到此错误:

  

“SQLSTATE [HY000] [1045]拒绝用户访问   '// username'@'localhost'(使用密码:YES)“

我的数据库连接如下:

  <?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和codeanywhere是否存在问题,或者我是否只是输错了phpmyadmin。谢谢。

1 个答案:

答案 0 :(得分:0)

检查你是否有一个mysql用户&#39;用户名&#39; @&#39; localhost&#39;使用mysql> select user,host from mysql.user;命令。如果您有一个条目作为主机127.0.0.1的用户名,则在您的连接参数中将localhost替换为127.0.0.1。或者添加一个mysql用户&#39;用户名&#39; @&#39; localhost&#39;然后再试一次。