PHP call to mysqli_query returns null (as expected) but I don't seem to be able to detect it
-
My SELECT query works fine when I've got records. Whether there are no records, or not in the result set I get a warning
Warning: mysqli_num_rows() expects parameter 1 to be mysqli_result, null given
I've tested the result agains
FALSE, NULL, null
(both null and NULL seem to be used in examples and the manual)and calling
is_null($result)
but I don't pick it up. Why? I just want to be able to differ between technical failure and return of zero records.
$query = 'SELECT CommentId, ParentId, Subject, Name, DATE_FORMAT(TimeStamp,"%k::%i %d-%m-%Y (GMT)"), Comment FROM commentdata WHERE ArticleId = ' . $ArticleId . ' ORDER BY COALESCE ( ParentId, CommentId)';
$result = mysqli\_query($connect, $query); if(TRUE == $result) { echo 'TRUE returned on query for data: ' . mysqli\_error($connect) . '
';
}if(FALSE == $result) { echo 'FALSE returned on query for data: ' . mysqli\_error($connect) . '
';
mysqli_close($connect);
die("Connection closed after FALSE returned on query for data: " . mysqli_error($connect));
}if(NULL == $result)) { echo 'NULL returned on query for data: ' . mysqli\_error($connect) . '
';
mysqli_close($connect);
die("Connection closed after NULL returned on query for data: " . mysqli_error($connect));
}if(null == $result)) { echo 'null returned on query for data: ' . mysqli\_error($connect) . '
';
mysqli_close($connect);
die("Connection closed after null returned on query for data: " . mysqli_error($connect));
}if(is\_null($result)) { echo 'NULL returned on query for data: ' . mysqli\_error($connect) . '
';
mysqli_close($connect);
die("Connection closed after NULL returned on query for data: " . mysqli_error($connect));
}/\* determine number of rows in result set \*/ $rowcount = mysqli\_num\_rows($result);