In this tutorial we will understand how to connect database in PHP so here I am making the object MySQLi and passing host name, username, password and DB name so this will help you to connect to database.


$conn = new mysqli("localhost", "root", "", "db_name");
// Check connection
if ($conn->connect_errno) {
    echo "Failed to connect to MySQL: " . $conn->connect_error;

$conn->connect_error if there is problem to connect to db it will show the error message