I keep getting this error and can't figure out why: "PHP Fatal error: Call to a member function query() on null"
All my mysqli calls work except within a function.
My connection.php file has:
$connection = new mysqli("localhost", "user", "pass", "db");
I've tried setting $connection as a global thinking this was a scope problem, but it's still a thing.
include('connection.php');
function text($x) {
$query = "SELECT * FROM content WHERE page='". $x ."'";
$result = $connection->query($query)->fetch_assoc();
return $result['column'];
}
test('home');
Querying outside of functions works fine.