I have a look at this code. please comment it out. thank you-php Tutorial.

Source: Internet
Author: User
Experts can help me read this code. please help me comment it out. thank you! PHPcode obtains the total number of records. the publicfunctionnum_rows ($ results) {$ results parameter is the returned result of select_query ($ SQL) if (! Is_bool ($ results) {*********** this place does not understand, why can I help you read this code, please help comment out, thank you!
PHP code
  // Obtain the total number of records. the public function num_rows ($ results) {// $ results parameter is the returned result of select_query ($ SQL) if (! Is_bool ($ results) {// *********** why is is_bool () used for reverse judgment? $ Num = mysql_num_rows ($ results); $ this-> write_log ("The number of retrieved records is". $ num); return $ num;} else {return 0 ;}}


------ Solution --------------------
In view of the following $ num = mysql_num_rows ($ results );
So if (! Is_bool ($ results) {yes
It is not a logical type. it cannot be said that it must be a resource type.
------ Solution --------------------
If an error occurs during execution of mysql_query (), the value of false (bool) is returned. Is used to determine this.
If (! Is_bool ($ results) {if it is not a bool value, the query is successfully executed; otherwise, the query fails.
------ Solution --------------------
It is worth noting that the parameter $ results
According to your function, the $ results parameter is the result of the database query.
In this case, it is no strange to use is_bool to determine whether the query is false .....

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.