class MySQLiConnection {
private static $conn = null;
private function __construct() { }
public static function getConnection() {
if (static::$conn === null) {
static::$conn = mysqli_connect(/* your params go here */);
}
return static::$conn;
}
}
Then you can replace all global $conn
with $conn = MySQLiConnection::getConnection()
4
solved Use of global for mysqli_insert_id()