I'm using some "beginner" masterpage-like in PHP, and I connect to the database from one page, but want to access it from an included page as well. I define the database variable above the include call, so there shouldn't be any problem there.
Currently, when including the page and checking if the variable is set, it returns false. How can I accomplish such thing instead of re-connecting in every include?
index.php
$db = new mysqli("HOST", "USERNAME", "PASSWORD", "DB");
include 'page2.php';
page2.php
if(isset($db))
echo 'set';
else
echo 'not set'; // this will be called
Update your page2.php like this. Hope your code will work fine now.
This should come like this
index.php
page2.php
Include
in php