0

I'm trying to connect my PHP to my XAMPP DB server, but as it seems I'm not doing something right. This is my code:

<?php

$servername = "localhost";
$username = "username";
$password = "password";
$db=  "blogdata";
// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
    die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?>

And it returns:

Warning: mysqli::__construct(): (HY000/1045): Access denied for user 'username'@'localhost' (using password: YES) in C:\xampp\htdocs\KungFu\Blog.php on line 8 Connection failed: Access denied for user 'username'@'localhost' (using password: YES)

I think everything is correct, tried different variations but as you can tell it is not working.

Dharman
  • 26,923
  • 21
  • 73
  • 125

1 Answers1

-2

Best way to connect php to MySQL is to use new method : PDO :)

PHP : $bdd = new PDO('mysql:host=localhost;dbname=test;charset=utf8', 'root', '');