Connectivity with mySQL

I am using the following code for connectivity with the mySQL:

<?php

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

// Create connection
$conn = new mysqli($servername, $username, $password);
 
// Check connection
if ($conn->connect_error) {
    die("Custom message - Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?> 

But, in return, I receive the following Error message:

Connection failed: Access denied for user ‘username’@‘localhost’ (using password: YES)

Would anybody help to a novice!

Thanks in anticipation and regards.

1 Like

Just checking - are ‘username’ and ‘password’ really your username and password for your database?

Thanks for the response. In my mind, I am creating a NEW database with the provided credentials. If I am wrong, please suggest.
Thanks.

Where were the credentials provided?

Are you using phpmyadmin on your local computer? If so, check out the users that are set up there.

Yes, you are wrong.

new mysqli means “to create a new PHP class instance” that have to be connected to database using existing account credentials.

Yes, I M running the code on my local PC and I have installed Webmatrix + PHP + sqlServer on the same machine. I am providing just the fictitious username & password to test my skill :-)smiley:

Sorry, Mr. colshrapnel. It means, I just misunderstood. Would U kindly suggest me the correct statement for creating a new database!

Raabi

You need to create the database in phpMyAdmin.

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.