首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Codeanywhere与Phpmyadmin数据库连接

Codeanywhere与Phpmyadmin数据库连接
EN

Stack Overflow用户
提问于 2018-04-17 05:27:50
回答 1查看 1.6K关注 0票数 0

我有一个困难的时间连接我的代码到我的phpmyadmin数据库。我收到这个错误:

“拒绝用户‘//用户名’@‘localhost’的SQLSTATEHY000访问(使用密码: YES)”

我的数据库连接看起来是:

代码语言:javascript
复制
  <?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;
    }
}
?>

我想知道我的本地主机和代码是否有问题,或者我只是简单地输入phpmyadmin错误。谢谢。

EN

回答 1

Stack Overflow用户

发布于 2018-04-17 07:28:25

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

票数 0
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/49870485

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档