php - mysqli array fetching is not getting data -




i have fetch result in single row can't run multiple rows. how can fix this?

$stmt = $this->conn->prepare("select * user id=?"); $stmt->bind_param("s", $id); if($stmt->execute()){  $result = $stmt->get_result()->fetch_array(mysqli_assoc);  $stmt->close();  return $result;  } 

i got result wise

{"id":2,"name":"anju"} 

but need user result .my code here

$stmt = $this->conn->prepare("select * user id=?"); $stmt->bind_param("s", $id); if($stmt->execute()){ $result = array(); while ($row = $stmt->get_result()->fetch_array(mysqli_assoc)) { $result[] = $row; }  $stmt->close();  return $result; } 

i got error

fatal error: call member function fetch_array() on non-object in line 5

the line is:

while ($row = $stmt->get_result()->fetch_array(mysqli_assoc))   

my expecting result

 {"id":1,"name":"obi"}, {"id":3,"name":"oman"}, {"id":4,"name":"anju"} 

$stmt = $this->conn->prepare("select * user id=?");
$stmt->bindvalue(1, $id);

try way

and try fetchall instead of fetch_array





wiki

Comments

Popular posts from this blog

Asterisk AGI Python Script to Dialplan does not work -

python - Read npy file directly from S3 StreamingBody -

kotlin - Out-projected type in generic interface prohibits the use of metod with generic parameter -