php - num_rows property is never predictable -
i tired of num_rows property. first using without store_result() , not working. found out should store results locally in order find out number of records. worked. again stopped working.
when check property requestedid return value. however, num_rows says zero. else missing?
$query="select requestedid friend_request requestingid=?"; $stmt=$mysqli->stmt_init(); $stmt->prepare($query); $stmt->bind_param('i',$requestinguserid); $stmt->execute(); $stmt->bind_result($requestedid); $stmt->fetch(); $stmt->store_result(); if($stmt->num_rows > 0) { return $requestedid; } else{ return 0; }
judging explanation on page: http://php.net/manual/en/mysqli-stmt.store-result.php
the store_result function needs called before fetch.
$stmt->execute(); /* store result */ $stmt->store_result(); printf("number of rows: %d.\n", $stmt->num_rows); /* free result */ $stmt->free_result(); you should able read results prior freeing them.
Comments
Post a Comment