I’m having trouble connecting to my database after reinstalling WAMP server. I’m using PHP PDO, but I keep getting an access denied error. Here’s my connection code:
class DbConnect {
private $host = 'localhost';
private $db = 'shop_system';
private $user = 'root';
private $pass = '';
public $connection;
public function __construct() {
if (!isset($this->connection)) {
try {
$dsn = "mysql:host={$this->host};dbname={$this->db}";
$this->connection = new PDO($dsn, $this->user, $this->pass);
$this->connection->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
} catch (PDOException $e) {
echo "Connection failed: " . $e->getMessage();
exit;
}
}
}
}
Any ideas why I’m getting this error? I’ve double-checked my database name and user credentials, but it’s still not working. Could it be a permissions issue with WAMP?