I have a programming problem in which I put my PDO-type connection in the header and need to have $pdo
called in any other file on the system. Example:
header.php
<?php require("configs/conexao.php"); ?>
index.php
<?php
require("header.php");
// todo o conteúdo
require("footer.php");
?>
footer.php
<?php
$consulta = $pdo->query("SELECT * FROM usuarios");
?>
My conexao.php
is this: PDO
We can notice that I called the PDO connection in the header because this file will be present on every page of the system and I want to be able to make a select in the footer because there is a need to if you call some information there.
I figured the fact that requires to link one file to another would cause $pdo
to travel to the footer but that is not the case. Then I have to call the connection.php file in the footer, which I imagine to be POG .
How can I then insert the connection file in the header and call the $pdo
in the footer or any other file if the need exists?
Update
- This is the only file I use to connect to the entire system, so the connection is not being closed. I'm going to enable PHP errors.