如何在zf2中的控制器中执行查询。请帮帮我
我的查询是这样的:
$fetchGeography = "select ggl.list_id
from gst_geography_list as ggl
join gst_position as gp on(ggl.list_id = gp.list_id)
join gst_employee_geography_relation as gegr on(gp.position_id = gegr.list_id)
where gegr.employee_id = '" . $id . "' ";
//var_dump($fetchGeography);die;
$fetchGeographyList = MainDbTable::selectProcStatic($fetchGeography);
答案 0 :(得分:0)
在ZF2中,首先需要MainDbTable
类中可用的数据库适配器 - > selectProcStatic
静态方法。
然后这样做 -
public static function selectProcStatic($sql = '') {
$resultSet = null;
if($sql !== '') {
$statement = $this->adapter->query($sql);
$resultSet = $statement->execute();
}
return $resultSet;
}
如果课程中有TableGateway
,请执行此操作 -
public static function selectProcStatic($sql = '') {
$resultSet = null;
if($sql !== '') {
$statement = $this->tableGateway->adapter->query($sql);
$resultSet = $statement->execute();
}
return $resultSet;
}
在任何情况下,必须使用db适配器。