Answer the question
In order to leave comments, you need to log in
Why can't I connect to the database?
For some reason, I can’t connect to the database either using PDO or using mysqli, I use OpenServer, for some reason it pops up:
Error!: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES)
$user = 'root';
$password='';
$host='localhost';
$db='site';
$charset='utf8';
$opt = [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
PDO::ATTR_EMULATE_PREPARES => false,
];
$req = "mysql:host=$host;dbname=$db;charset=$charset";
try {
$pdo = new PDO($req,$user,$password);
} catch (PDOException $e){
print "Error!: " . $e->getMessage() . "<br/>";
}
Answer the question
In order to leave comments, you need to log in
Access denied for user 'root'@'localhost' (using password: YES)
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question