-1

i'm new to mysqli trying to select everything from a table but num_rows function is returning 0 what am i doing wrong?

here is my code

    <?php $conn = new mysqli('localhost', 'root', '', 'paa');
    $sql='SELECT * FROM utilisateurs';
    $rs=$conn->query($sql);
    if($rs === false) {
    trigger_error('Wrong SQL: '.$sql.'Error:'.$conn>error,E_USER_ERROR);
      } else {
      $rows_returned = $rs->num_rows;
      echo $rows_returned;
      }

   ?>
Ayat
  • 15
  • 1

2 Answers2

0

Apart from the $conn>error,E_USER_ERROR which should be $conn->error,E_USER_ERROR there is no error in your code. Maybe the table is empty?

mevdschee
  • 1,625
  • 19
  • 16
  • the table is not empty :/ i can't figure out what's wrong – Ayat Oct 17 '15 at 09:22
  • I ran the code on my local machine (default PHP 5.5.9 on Ubuntu 14.04) with a real table it gave the correct result. IMHO the code is not the problem unless this is related to a bug in a specific PHP version. Why the downvote? – mevdschee Oct 17 '15 at 20:02
0

This function returns the number of rows found by the query. 0 means that your query returned no rows.

The question why did it so is neither on topic not have any means to be answered.

Your Common Sense
  • 156,878
  • 40
  • 214
  • 345