[英]mysql fetch() return null values
I'm really new to php, I wanted to get data that has been stored before using fetch(). 我真的是php新手,我想获取使用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: 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. 您好,我认为您向getAllDevices函数返回了错误的值。
remove the comment from this "$result = $stmt->get_result()". 从此“ $ result = $ stmt-> get_result()”中删除注释。
and return the $result variable instead of $stmt. 并返回$ result变量而不是$ stmt。
try this 尝试这个
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.