1
I have a programming problem in which I put my PDO type connection in the header and I need that $pdo
be called in any other system file. 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");
?>
Man conexao.php
is this: PDO
We can notice that I called the PDO connection in the header because this file will be present on all pages of the system and I want to be able to make one select on the footer because there is a need to call some information there.
I imagined that the fact of requires linking one file to the other would cause the $pdo
travel to the footer but that’s not what happens. Then I have to call the file php connection. on the footer, which I imagine is about POG.
How can I then insert the connection file into the header and call the $pdo
in footer or any other file if necessary?
Updating
- This is the only file I use to connect to the entire system, so the connection is not being closed. I will activate PHP errors.
Apparently that should work. It may be that the includes do not work on a certain page because of relative paths (and you have the warnings and errors turned off); it may be that you have something in your code closing the connection or preventing new queries from running; it may be several things, I find it difficult to answer with certainty only with the information you posted.
– bfavaretto