-2

I got stuck at this. i am using hostinger for my website

    $server = "localhost";
    $user = ""; //Username
    $password = ""; //Password
    $database = ""; //Database
    $connection = mysqli_connect($server,$user,$password,$database);

    if (mysqli_connect_errno()) {
      echo "Failed to connect to MySQL: " . mysqli_connect_error();
      exit();
    }

This is my code. i could not find a relevant answer. Thanks in advance.

  • 1
    The error is explicit, `Access is denied for user`. You need to sort this out with your hosting provider. – waterloomatt May 11 '22 at 15:06
  • https://www.hostinger.com/tutorials/how-to-connect-php-to-mysql – waterloomatt May 11 '22 at 15:08
  • I am also using the official documentation of hostinger but i dont know what is the issue i am a beginner – XtyLish Sam May 11 '22 at 15:19
  • Have you created the database and set up a user with a password for that database? You'll also need to give that user permissions like `SELECT`, `UPDATE`, etc. All that is done through the hosting provider's website. Reach out to them if you get stuck. – waterloomatt May 11 '22 at 15:34
  • Everything is done. as documentation stats with permissions – XtyLish Sam May 11 '22 at 15:37

2 Answers2

0

thanks for helping me. it was hosting issue. i mailed to the support system of the hostinger. they told me to change my database password and then update the script. i follow the instructions and my error was solved. Thank You All.

-1

Are you sure that localhost is the right host? I would also dump the mysqli_connect_errno() value because it returns the error code from the last connection attempt, which will give you a very good indication of where the issue is. and I would check if the user u201944136_root is defined and have permissions against localhost (mysql> SHOW GRANTS FOR 'u201944136_root'@'localhost';)

d3javu999
  • 323
  • 1
  • 8