Access denied for user 'username' @ 'localhost' (using password: NO)
×


Access denied for user 'username' @ 'localhost' (using password: NO)

0 248

Whenever we create a project using PHP Technology and want to connect with database (Store the Data) using MySql or MySqli, we have to make sure that database is created, with a particular credential. When we try to connect PHP code script with database, we somehow faced error says:

| Access denied for user 'username'@'localhost' (using password: NO)

This error is generally caused because of wrong (hostname, username, password, database name) entered by the developer.

For example:

<?php
error_reporting(0);
session_start();
$conn=mysqli_connect('localhost','root','','db_name');
if (mysqli_connect_errno())
{
echo "Failed to connect to MySQL: " . mysqli_connect_error();
}
mysqli_set_charset($conn,"utf8");
?>

If the username, db_name and hostname not matched with the exact database then the output will be:

Output:-

Failed to connect to MySQL:

| Access denied for user 'username'@'localhost' (using password: NO)

The Solution for the above error can be we have to make sure that the database has been created properly and the accurate hostname, Username and database name should be entered by the developer when connecting to the database in PHP code script.

It will definitely resolve the above error.



Best WordPress Hosting


Share:


Leave a Reply


Comments
    Waiting for your comments