问题
I want to ask why am I getting this error:
Trying to get property 'num_rows' of non-object
with the following code:
$sql = "SELECT * FROM $table_name ORDER BY Author";
$result = $mysqli->query($sql);
if ($result->num_rows > 0) {...
I have used echo $sql
to look if the problem lies there, but there is no problem. My SQL looks fine.
I have tried to use Prepared Statements
and got other errors too.
The line which gives the error is the one with the if
statement.
Any ideas?
回答1:
This is a better (non-error checking) pattern to follow IMO:
$sql = "SELECT * FROM $table_name ORDER BY Author";
$result = $mysqli->query($sql);
if (!empty($result)) {
You should also consider using PDO
来源:https://stackoverflow.com/questions/50975752/error-trying-to-get-property-num-rows-of-non-object