How can I connect to a MySQL database using PHP? Example code. - Biz Tech

How can I connect to a MySQL database using PHP? Example code.

Listen
$servername = "localhost";
$username = "yourusername";
$password = "yourpassword";
$dbname = "yourdatabase";

// Create connection
$conn = mysqli_connect($servername, $username, $password, $dbname);

// Check connection
if (!$conn) {
    die("Connection failed: " . mysqli_connect_error());
}
echo "Connected successfully";