3
votes

I'm trying to learn php but when I attempt to connect to a mysql database, I get this error. I don't think anything is wrong with the code itself but perhaps there is an error on the hosts side? I'm using 000webhost so.

Warning: mysqli::mysqli() [mysqli.mysqli]: (28000/1045): Access denied for user 'a7976620_db1user'@'localhost' (using password: YES) in /home/a7976620/public_html/index.php on line 17

Here is my php:

<?php

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

// Create connection
$conn = new mysqli($servername, $username, $password);

// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
echo "Connected successfully";
?> 
1
check your username and password.Sumit Pandey
I removed the password if you're talking about the ******Sokaz
clearly saying that permission issuePathik Vejani
Can you specify the DB name also as the fourth parameterSumit Pandey

1 Answers

-1
votes

In https://www.000webhost.com, there are two options in the cPanel:

  1. Fix ownership and
  2. Fix file permissions

You can apply this and it will be fine.