我正在构建以下PHP应用程序。我在一个名为Board的类中有一个函数。在该函数中,您将看到一个Query执行内部联接,表用户将ID与过滤器相关联。这是功能;
A-C提供的解决方案
$ boards = $ statementBoards-> fetch 全部(PDO :: FETCH_ASSOC);
public function loadBoards($userID)
{
$conn = Db::getInstance();
$statementBoards = $conn->prepare("SELECT board.boardID,
board.userID, board.private, board.boardTitle, users.firstname,
users.lastname FROM
board INNER JOIN users ON board.userID=users.id WHERE
board.userID = :userID;");
$statementBoards->bindValue(':userID', $userID);
$statementBoards->execute();
$boards = $statementBoards->fetch(PDO::FETCH_ASSOC);
return $boards;
}
在前端我打印以下内容:
$b = new Board();
$userID = $_SESSION['id'];
$boards= $b->loadBoards($userID);
var_dump($boards);
Wich给了我以下结果:
array(6) { ["boardID"]=> string(2) "29" ["userID"]=> string(2) "93"
["private"]=> string(1) "1" ["boardTitle"]=> string(14) "MyBoard"
["firstname"]=> string(5) "NameTest" ["lastname"]=> string(5)
"TestName" }
但是,查询应显示多个结果,因此我期待多个数组。我错过了什么?
提前致谢!