我有这个功能:
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; }
下表如下所示:
|user_id|follower_id| | 2 | 5 | | 3 | 5 | | 4 | 5 |
$following必须是一个行数组.实际上你只是获取第一行.使用
原文链接:https://www.f2er.com/php/139163.htmlPDOStatement::fetchAll()
获取它,如下所示:
$following = $stmt->fetchAll(PDO::FETCH_ASSOC);