I'm creating a site where several pages need to connect to the bank to perform their operations, for example, I made a login system, so the user clicks on 'login' opens a bootstrap modal to enter the data . I created the page "validaLogin.php" to do the checks of the users and put a require "validalogin.php";
in the navbar to call such page. What happens is this: inside this page I make the connection to the bank to perform the operations, but when I open a page that also needs to connect to the bank, the error "connectMySQL" has already been declared and can not be redeclared.
In short: Two pages are calling the same connection function twice and gives the error, is there any way to make a single site-wide connection?
function conectaAoMySQL(){
$conn = new mysqli(HOST, USER, PASSWORD, DATABASE);
if ($conn->connect_error)
throw new Exception('Falha na conexão com o MySQL: ' . $conn->connect_error);
return $conn;
}