In your code you're mixing both procedural and object-oriented code. Choose either one or the other. Here's how you would solve the problem the procedural way.
$result = mysqli_query($link, $sql, MYSQLI_USE_RESULT)
I'm getting the Call to a member function query() on a non-object when
I try to call my function.
That's because the $mysqli
object is not declared anywhere (or is it)? Before you can use $mysqli
you should first create an instance of mysqli
and assign it to your object.
$mysqli = new mysqli("localhost", "my_user", "my_password", "database");
Only then you may call the methods of the mysqli class like $mysqli->query();
The error you made depends probably on two misconceptions:
1) you pasted half of your code from the procedural-style part of the mysqli manual and half from the oop part
2) you assume $mysqli
is a global object instantiated with $mysqli_connect();
. It is not. You should invoke the constructor with the new
keyword if you'd like to use it as an object.