I’m converting from MySQL to MySQLi and I noticed that if I am limiting to one row in the mysql query, is it necessary for me to check if the number of rows is 1? After all, the rows that can be returned is 0 or 1.
Here is the code I currently use (untested as I am converting from mysql to mysqli):
$query = "SELECT email,auth,username FROM user_list WHERE id = '".$user["id"]."' LIMIT 1";
$query = $mysqli->query($query);
if($query and $query->num_rows() == 1)
{
Everything you should check is that if a query returned 0 or more rows.
It won’t return more than specified by
LIMITclause, but it can return 0 if no matches found.Btw, MySQLi is just an extension that allows you to access the functionality provided by MySQL 4.1+. It’s still the MySQL.