在 php 中,我试图访问与其用户 ID 匹配的所有 DeviceID。它只返回其中一个,即 MySQL 表中的第一个。
这是我的代码。我该如何解决这个问题。
if (!$query = $db->prepare('SELECT ALL * FROM DeviceIDs HAVING UserID=:id')) {
exit('{"result": "something went wrong preparing the query"}');
}
if (!$query->execute(array(':id' => $secondData["id"]))) {
exit('{"result": "something went wrong executing query"}');
}
$thirdData = $query->fetch(PDO::FETCH_ASSOC);
echo '' . json_encode($thirdData);
最佳答案
您必须使用循环迭代获取方法的返回,例如:
while ($row = $query->fetch(PDO::FETCH_ASSOC)) {
$thirdData[] = $row;
}
print_r($thirData);
关于php - 从具有 UserID= :id in php only returns one instance? 的设备 ID 中选择所有 *,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/26456996/