What is the simplest way to judge the result set empty in mysqli

Source: Internet
Author: User
What is the simplest way to judge the result set to be empty in mysqli
I found that judging the result set is not empty generally want to write this:

if ($result->num_rows>0) {}

And you can't write this:

if ($result)

I use Var_dump ($result); output, the result is


Object (Mysqli_result) #2 (0) {}

Visible, when the result set is empty, $result is an empty object with no members, I read the book said that when the object is converted to a Boolean, no member of the objects will be converted to false, otherwise converted to true, why here this empty object does not convert to false.

I also want to ask MySQL and PDO to determine the result set is empty also have to determine the number of records property is 0.

Share to:


------Solution--------------------
Yes, the result set is empty in MySQL and PDO, and you have to judge the number of records to be 0.

  • Contact Us

    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.

    A Free Trial That Lets You Build Big!

    Start building with 50+ products and up to 12 months usage for Elastic Compute Service

    • Sales Support

      1 on 1 presale consultation

    • After-Sales Support

      24/7 Technical Support 6 Free Tickets per Quarter Faster Response

    • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.