Is it possible to establish a global database connection outside of a class in PHP and make the mysqli object globally accessible without passing it every time?

To establish a global database connection outside of a class in PHP and make the mysqli object globally accessible without passing it every time, you can use the global keyword to declare the mysqli object as a global variable. This way, you can access the database connection throughout your PHP scripts without passing it as a parameter.

<?php

$mysqli = new mysqli("localhost", "username", "password", "database");

if ($mysqli->connect_error) {
    die("Connection failed: " . $mysqli->connect_error);
}

global $mysqli;

// Now you can access the $mysqli object globally in your PHP scripts