php code is being read word for word instead of connecting to the database

This is my code.

<?php

$servername = "localhost";
$username = "username";
$password = "password";

// Connection
$conn = mysqli_connect($servername, 
            $username, $password);

// Check if connection is 
// Successful or not
if (!$conn) {
die("Connection failed: "
    . mysqli_connect_error());
}
echo "Connected successfully";
?>

this is the result on the browser.

Fatal error: Uncaught mysqli_sql_exception: Access denied for user ‘root’@’localhost’ (using password: YES) in C:xampphtdocsTestshat.php:8 Stack trace: #0 C:xampphtdocsTestshat.php(8): mysqli_connect(‘localhost’, ‘root’, Object(SensitiveParameterValue)) #1 {main} thrown in C:xampphtdocsTestshat.php on line 8 ?>

I tried putting the database into the code and it still produces the same error result. I also tried using the PDO version of the code from Geeksforgeeks instead of mysqli. Still did not work.

My current xampp setup is newly downloaded and I am using xampp windows 8.2.12.

I am trying to connect my database to my php file.