Hi. It's a very simple and stupid question
while using mysqli extension let's say I get some info from the db, related to the website's settings. Something like this
$mysqli = new mysqli ("host","user","password","tb");
if (mysqli_connect_errno()) die ("Error: ".mysqli_connect_errno()." - ".mysqli_connect_error());
if ($result = $mysqli->query("SELECT * FROM settings")) {
$settings = $result->fetch_array();
$result->close();
}
$mysqli->close();
But this is in one file (core.php), after this one I include the header.php, i have the main page, a footer.php, maybe one or two more include files (sidebar maybe). So, I'll need more info from the db.
I believe I should create a new mysqli instance in the "core.php" file, do what I have to do and close it in the "footer.php" file, when all the job is done. Don't you think? I believe this is easier but I don't know sh*t about this, so if you could just tell me if that's the right thing to do I'd really appreciate it. I just don't think opening and closing connections over and over would be a smart thing to do. I believe this is common sense but, as I said, I don't know much about this so maybe there's a better way. Or not.
Thanks.