How to reuse a MySQLi connection

I’ve ran into an issue with user already has more than ‘max_user_connections’ active connections

This happens because I use functions for the website functionality, each function contains a

$mysqli = connect();

Though at the same time, each function closes the mysqli at the end of function

mysqli_close($mysqli);

I do not want to include $mysqli as a parameter of the function, as the function is dynamic and would be tiresome to include it with each function call.

the connect() function just contains:

$mysqli = new mysqli(...);
return $mysqli;

I believe the error is thrown because the function sometimes calls itself for different executions, based on user input and pre-requisites… even though the mysqli is closed at the end of the function

I’d like to know if there is a way of re-using a $mysqli connection sort of like in a global way…

I’m not sure whether I’ve explained myself fully so if you need some more information please leave a comment.