我很难将我的代码连接到我的 phpmyadmin 数据库。我收到此错误:
“SQLSTATE [HY000] [1045] 用户'//用户名'@'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。谢谢你。