Request -

$q = $this->db->query("SELECT text FROM page WHERE id = '".$pageId."'"); 

echo $q->num_rows; displays 1.

Request -

 $stmt = $this->db->prepare("SELECT text FROM page WHERE id=?")){ $stmt->bind_param('i',$pageId); $stmt->execute(); echo $stmt->num_rows; 

displays 0.

  • I don’t really know anything about pdo, but you have in the first WHERE id = '25' query WHERE id = '25' (in quotes), in the second case, not. This is the difference - splash58
  • this is the syntax of mysqli. bind_param substitutes instead? specified value. - terantul
  • I understand this, I just wrote to you about what in the second case would be without quotes where id=25 for example, unlike the first. How this may affect the result, I do not know - splash58

1 answer 1

Before calling num_rows, use store_result .

num_rows

Returns the number of rows in the query result. The result of running mysqli_stmt_num_rows () depends on whether mysqli_stmt_store_result () was used to buffer the result of the selection in the descriptor.


People already stumbled 1 , 2