I'm really new to php, I wanted to get data that has been stored before using fetch(). It return the exact number of rows in the database, but with null values.
ini_set('display_errors', 1);
require_once 'DbOperation.php';
$db = new DbOperation();
$devices = $db->getAllDevices();
$response = array();
$response['error'] = false;
$response['antrian_mobile'] = array();
while($device = $devices->fetch()){
$temp = array();
$temp['id']=$device['id'];
$temp['email']=$device['email'];
$temp['token']=$device['token'];
array_push($response['antrian_mobile'],$temp);
}
echo json_encode($response);
the function of getAllDevices:
public function getAllDevices(){
$stmt = $this->con->prepare(" SELECT email, token FROM antrian_mobile ");
//$stmt->bind_param("s",$email);
$stmt->bind_result($email,$token);
$stmt->execute();
//$stmt->store_result();
//$result = $stmt->get_result();
return $stmt;
}
what is wrong with this code?
Hello i think you had return wrong value into getAllDevices function.
remove the comment from this "$result = $stmt->get_result()".
and return the $result variable instead of $stmt.
try this