I have a problem in my php that I need to include all the time the config.php (mysqli php connection script)
<?php
$root = $_SERVER['DOCUMENT_ROOT'];
include("$root/config.php"); // INCLUDE CONFIG
$stmt = $mysqli_link->prepare("SELECT id, categoria FROM categoria order by rand() limit 10");
$stmt->execute();
$stmt->bind_result($id1, $categoria);
include("$root/config.php"); // NEED TO INCLUDE CONFIG AGAIN TO AVOID - Fatal error: Call to a member function bind_param()
while($stmt->fetch()) {
$stmt2 = $mysqli_link->prepare("SELECT id, categoria, cover, fotos, titulo, descricao, data FROM posts where categoria = ? order by id desc limit 1");
$stmt2->bind_param('i', $id1);
$stmt2->execute();
$stmt2->bind_result($id, $categoria, $cover, $pictures, $titulo, $descricao, $data);
$stmt2->fetch();
echo"<li class=liside><img src=/$picture class=row><a href=/category/$categorialink>$categoria</a></li>";
}
?>
What am I doing wrong? I need first the $stmt to select categories, after that $stmt2 inside while to get things from that category on post table.
config.php
$hostname="localhost";
$titulo="config";
$user="root";
$pass="";
$bd="site";
$mysqli_link = new mysqli($hostname, $user, $pass, $bd);
$mysqli_link->set_charset("utf8");
ini_set('default_charset','utf8');