我有一个困难的时间连接我的代码到我的phpmyadmin数据库。我收到这个错误:
“拒绝用户‘//用户名’@‘localhost’的SQLSTATEHY000访问(使用密码: 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;
}
}
?>我想知道我的本地主机和代码是否有问题,或者我只是简单地输入phpmyadmin错误。谢谢。
发布于 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’,然后再试一次。
https://stackoverflow.com/questions/49870485
复制相似问题