[英]PDO::FETCH_ASSOC not fetching everything
I have this function: 我有这个功能:
function get_following($user_id) {
global $conn;
$stmt = $conn->prepare("SELECT * FROM following WHERE `follower_id`=:user");
$stmt->bindParam(':user', $user_id, PDO::PARAM_INT);
$stmt->execute();
$following =$stmt->fetch(PDO::FETCH_ASSOC);
return $following;
}
The following
table looks like this: following
表如下所示:
|user_id|follower_id|
| 2 | 5 |
| 3 | 5 |
| 4 | 5 |
Now the problem is when I actually call the function it only selects one of the rows from the table, where my follower_id = 5. 现在的问题是,当我实际调用该函数时,它仅从表中选择一行,其中follower_id = 5。
$following will have to be an array of rows. $ following必须是一个行数组。 You are actually only fetching the first row.
您实际上只是在获取第一行。 Fetch it using
PDOStatement::fetchAll()
, like this: 使用
PDOStatement::fetchAll()
来获取它,如下所示:
$following = $stmt->fetchAll(PDO::FETCH_ASSOC);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.