I want to know if it is okay/safe to use a prepared statement and mysqli_num_rows
like this:
public function getUnreadNumber() {
$userLoggedIn = $this->user_obj->getUsername();
// get_result for * and bind for select columns
// bind_result Doesn't work with SQL query that use *
$query = $this->con->prepare('SELECT * FROM notifications WHERE viewed="0" AND user_to = ? ');
$query->bind_param("s", $userLoggedIn);
$query->execute();
$query_result = $query->get_result();
return mysqli_num_rows($query_result);
}
Or should I do this?
$query = $this->con->prepare('SELECT * FROM notifications WHERE viewed="0" AND user_to = ? ');
$query->bind_param("s", $userLoggedIn);
$query->execute();
$query_result = $query->get_result();
$numRows = $query_result->num_rows;
return $numRows;
return mysqli_num_rows($query_result)
\$\endgroup\$ – user13477176 Jul 15 '20 at 19:11this->user_obj->getUsername()
?? \$\endgroup\$ – Sᴀᴍ Onᴇᴌᴀ Jul 16 '20 at 5:34