Php 如何在zf2中的控制器中执行查询

Php 如何在zf2中的控制器中执行查询,php,mysql,zend-framework2,Php,Mysql,Zend Framework2,如何在zf2中的控制器中执行查询。请帮帮我 我的问题是这样的: $fetchGeography = "select ggl.list_id from gst_geography_list as ggl join gst_position as gp on(ggl.list_id = gp.list_id)

如何在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);

在ZF2中,首先需要在
MainDbTable
class->
selectProcStatic
static方法中提供db适配器

那就这样做吧-

public static function selectProcStatic($sql = '') {
    $resultSet = null;

    if($sql !== '') { 
        $statement = $this->adapter->query($sql); 
        $resultSet = $statement->execute();
    }

    return $resultSet;
}
public static function selectProcStatic($sql = '') {
    $resultSet = null;

    if($sql !== '') { 
        $statement = $this->tableGateway->adapter->query($sql); 
        $resultSet = $statement->execute();
    }

    return $resultSet;
}
如果类中有可用的
TableGateway
,请执行此操作-

public static function selectProcStatic($sql = '') {
    $resultSet = null;

    if($sql !== '') { 
        $statement = $this->adapter->query($sql); 
        $resultSet = $statement->execute();
    }

    return $resultSet;
}
public static function selectProcStatic($sql = '') {
    $resultSet = null;

    if($sql !== '') { 
        $statement = $this->tableGateway->adapter->query($sql); 
        $resultSet = $statement->execute();
    }

    return $resultSet;
}

在任何情况下,都必须使用db适配器。

这是zf2吗?似乎zf1是的,这是zf1代码。但我正在尝试用zf2编写此代码。好的,那么下面的答案是正确的:)我使用此selectProcStatic函数功能工作正常,但有一些问题$statement=$This->tableGateway->select($sql);var_dump($报表);不返回任何内容。我正在ZF2.do foreach($r)中的AlbumTable.php文件中对结果编写代码,然后在foreach中进行var_dump($r)