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 .....