How to connect PHP with MySQL

Website URL

(please specify the URL of the site on which you are experiencing the problem)

###No errors

(please share the FULL error message you see, if applicable)

I made a dadabase in MySQL and try to connect by script in PHP

$conn = new mysqli($servername, $username, $password,$dbname);
I got the name of db from MySQL and name and password from cpanel.,
MySQL Host Name : sql300.epizy.com as servername, but connection do not work.
Where is the problem ? In servername?

Why not? What do you see?

Please try to get the actual error message from the connection. That could look something like this:

$conn = new mysqli($servername, $username, $password,$dbname);
if ($conn->connection_error) {
    die("Database connection error: ".$mysqli->connect_error)
}

Once you have the actual connection error, please check it against the error messages in this article to learn what might be causing it:

3 Likes

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