I am trying to make a function page that will open and close the db using mysqli, but it’s not working. Is this possible or do I have to literally open and close it everytime? Here is the code from the functions.php page:
function opendb(){
$mysqli = new mysqli();
$mysqli->connect($host, $user, $pw, $db);
}
function closedb(){
$mysqli->close();
}
function rundb($query){
$result = $mysqli->query($query);
return $result;
}
Now, the opendb() function works when called, but the closedb() function returns the following error:
Fatal error: Call to a member function close() on a non-object
I simply needed to include the opendb and closedb operations into the rundb function. Once I did that, it worked perfectly.