In mysqli, what is the simplest way to determine whether the result set is empty?
Source: Internet
Author: User
In mysqli, the easiest way to determine whether a result set is empty is. I found that the result set is not empty. this is generally the case: if ($ result-& gt; num_rows & gt; 0) & nbsp ;{& nbsp ;}but cannot be written like this: if ($ result) I use var_dump ($ result); output, the result is & n. In mysqli, what is the simplest method to determine whether the result set is null?
I found that the judgment result set is not empty and should be written as follows:
If ($ result-> num_rows> 0 ){}
But cannot write it like this:
If ($ result)
I use var_dump ($ result); output, the result is
Object (mysqli_result) #2 (0 ){}
It can be seen that when the result set is empty, $ result is an empty object with no members. I read the book that when the object is converted to a Boolean object, the object without members will be converted to false, otherwise, convert it to true. why is this empty object not converted to false.
I also want to ask if mysql and PDO have to judge that the number of records attribute is 0 if the result set is null. Share To: num_rows> 0 )? {?} But you cannot write it like this: if ($ result) I use var_dump ($ result); output, close... 'data-pics = ''>
------ Solution --------------------
Yes. in mysql and PDO, if the result set is null, the number of records must be 0.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.