0
I am creating a site where several pages need connection to the database to perform their operations, for example, I made a login system, so the user clicks 'login' opens a modal in bootstrap to enter the data. I created the "validaLogin.php" page to do the user checks and put a require "validalogin.php";
on the navbar to call such a page. What happens is the following: within this page I make the connection to the bank to perform the operations, but when I open a page that also needs connection to the bank, the error "connects to MYQL" has already been declared and cannot be redeclared.
In short: Two pages are calling the same connection function with the bank twice and gives the error, there is some way to make a connection only for the whole site?
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;
}
use require_once or include_once depending on your need rather than require alone or include alone
– Anderson Henrique
Search the design Pattern Lazy loading
– Julio Henrique