我有这个功能:
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 |
现在的问题是,当我实际调用该函数时,它只从表中选择一行,其中我的 follower_id = 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.
$following 必须是一个行数组.您实际上只是在获取第一行.使用 PDOStatement::fetchAll() 获取它,如下所示:
$following will have to be an array of rows. You are actually only fetching the first row. Fetch it using PDOStatement::fetchAll(), like this:
$following = $stmt->fetchAll(PDO::FETCH_ASSOC);
这篇关于PDO::FETCH_ASSOC 未获取所有内容的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持html5模板网!
PHP、MySQL PDOException 的死锁异常代码?Deadlock exception code for PHP, MySQL PDOException?(PHP、MySQL PDOException 的死锁异常代码?)
PHP PDO MySQL 可滚动游标不起作用PHP PDO MySQL scrollable cursor doesn#39;t work(PHP PDO MySQL 可滚动游标不起作用)
PHP PDO ODBC 连接PHP PDO ODBC connection(PHP PDO ODBC 连接)
使用 PDO::FETCH_CLASS 和魔术方法Using PDO::FETCH_CLASS with Magic Methods(使用 PDO::FETCH_CLASS 和魔术方法)
php pdo 只从 mysql 获取一个值;等于变量的值php pdo get only one value from mysql; value that equals to variable(php pdo 只从 mysql 获取一个值;等于变量的值)
MSSQL PDO 找不到驱动程序MSSQL PDO could not find driver(MSSQL PDO 找不到驱动程序)