0

我是 Zend Framework 2 的新手,我目前正在为一个学校项目编写一个论坛。我有一个无法使用 Db Sql Select 对象和 tableGateway 管理的查询。我刚刚使用了一个 Db 适配器,它工作正常,但我正在寻找一种通过使用 Db Sql Select 对象来传递我的查询的方法,因为我稍后需要使用分页器。

这是我所拥有的:

public function fetchAll()
 {
    $select = $this->adapter->query(
           'SELECT theme.nom AS nom, theme.idTheme AS idTheme, theme.TidAdmin AS TidAdmin, theme.description AS description, users.username, Dnom, date, admin.pseudo AS apseudo
            FROM theme
            LEFT join (select DidUsers, Dnom, DidTheme, date from discussion group by date ) D ON `DidTheme` = theme.`idTheme` 
            LEFT JOIN users on DidUsers = idUsers
            LEFT JOIN admin on TidAdmin = idAdmin'
            );
    $statement = $select;
    $results = $statement->execute();
    return iterator_to_array($results);
 }

关于如何使用 Zend\Db\Sql\Select 执行此查询的任何想法?谢谢 !

4

1 回答 1

0
$subquery = new \Zend\Db\Sql\Select ('discussion');
$subquery->group ("date");
$subquery->columns (["DidUsers" , "Dnom", "DidTheme", "date"]);

$query = new \Zend\Db\Sql\Select ('theme');
$query->columns (['nom', 'idTheme', 'TidAdmin', 'description']);
$query->join ($subquery, 'idTheme = DidTheme');
$query->join ('users', 'idUsers = DidUsers', ['username']);
$query->join ('admin', 'idUsers = TidUsers', ['pseudo' => 'apseudo']);
于 2015-12-13T05:09:27.477 回答