To solve the "assignment in the condition", use! == false slows down the script. What for?

I am using zend studio for encoding in php.

In zend studio the while... line while... in the following code shows an assignment in condition warning, but it works fine and shows me tables instantly.

 $oDB = new db; print '<strong>Twitter Database Tables</strong><br />'; $result = $oDB->select('SHOW TABLES'); while ($row = mysqli_fetch_row($result)) { print $row[0] . '<br />'; } 

But when I solve this warning with the following code, it does not show a warning in zend studio , but it shows me tables after a long time of 20 to 30 seconds and a long space according to the results. Why?

 $oDB = new db; print '<strong>Twitter Database Tables</strong><br />'; $result = $oDB->select('SHOW TABLES'); while (( $row = mysqli_fetch_row($result)) !==FALSE) { print $row[0] . '<br />'; } 
+4
source share
1 answer

According to the manual :

mysqli_fetch_row () returns an array of strings matching NULL if there are no more rows in the result set.

You are checking the BOOL response, so the script continues. Use either! = FALSE or! == NULL.

The code will be either:

 while (($row = mysqli_fetch_row($result)) != FALSE) { 

OR

 while (($row = mysqli_fetch_row($result)) !== NULL) { 
+5
source

All Articles