My main page calls many database functions, stored in the db.php file. In each of them, I'm connecting to the MySQL database using
$connect = mysqli_connect(SERVER_NAME,SERVER_USER,SERVER_PASS,SERVER_DB);
and then after some queries, I'm closing it with
mysqli_close($connect);
No problem so far. But I want to know is there any way to make the code faster, by executing the connection just one time in the main code, at top of all DB function calls? and then closing the connection at the bottom of the main code?
In other words, How to access a variable (here $connect) which is outside of a function, without having to pass it as a parameter to that certain function?
I tried declaring $connect as global or static But none of them worked.