CodeIgniter Forums
mysqli num rows blows up the script - Printable Version

+- CodeIgniter Forums (https://forum.codeigniter.com)
+-- Forum: Using CodeIgniter (https://forum.codeigniter.com/forumdisplay.php?fid=5)
+--- Forum: General Help (https://forum.codeigniter.com/forumdisplay.php?fid=24)
+--- Thread: mysqli num rows blows up the script (/showthread.php?tid=65133)



mysqli num rows blows up the script - cupboy - 05-03-2016

What is wrong with the below code. It fails on the num_rows, but gives no error message.. it just doesn't go beyond that point. This isn't actually codeignitor code, it's just straight PHP.
Code:
if($q = $mysqli->query($sql)) {
      //if($q->num_rows == 0)
       // echo "no rows!";
       fputs($file,"query has completed!".PHP_EOL);
       fflush($file);
       /* fetch associative array */
       $countRows = $q->num_rows(); // <== won't go past this
       fputs($file,"rows returned: ".$countRows.PHP_EOL);



RE: mysqli num rows blows up the script - Narf - 05-09-2016

mysqli_result::$num_rows is a property, not a method.

You've used it correctly on the second line (but commented it out).