How to connect to the mysql database in php?

This question is often asked by the new PHP Developer who is trying to learn PHP themselves.

Here’s the syntax:

<?php

//connect to the db
$mysqli = new mysqli("hostname","db_username","db_password","db_name");

// Check connection
if ($mysqli->connect_errno) {
  echo "Failed to connect: "