How can one ensure that the MySQL connection is established before calling MySQL functions in PHP?

To ensure that the MySQL connection is established before calling MySQL functions in PHP, you can use the `mysqli_connect()` function to establish a connection and store it in a variable. Then, you can check if the connection was successful before proceeding with any MySQL functions.

// Establish MySQL connection
$connection = mysqli_connect("localhost", "username", "password", "database");

// Check if the connection was successful
if (!$connection) {
    die("Connection failed: " . mysqli_connect_error());
}

// Proceed with MySQL functions here
// For example:
$query = "SELECT * FROM table";
$result = mysqli_query($connection, $query);