Sql 使用 Zend Framework 2 tableGateway 查询
Sql Query with Zend Framework 2 tableGateway
我是 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 执行此查询的任何想法?
谢谢 !
$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']);
我是 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 执行此查询的任何想法? 谢谢 !
$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']);