SQL Raw数据查询

时间:2014-11-05 22:20:41

标签: zend-framework2 zend-db

您好我正在尝试查询这样的数据

    $sql = "SELECT *
            FROM company";

    $stmt = $this->getDbAdapter()->query($sql, \Zend\Db\Adapter\Adapter::QUERY_MODE_EXECUTE);

    if ($stmt instanceof \Zend\Db\ResultSet\ResultSet) {

        foreach ($stmt as $row) {
            $entities[] =$row;
        }
    }

但是我收到500内部服务器错误,这段代码有问题吗?

我已经完成了这个并且工作正常。

    $sql = "SELECT company.*,address_home.*,address_billing.*, T1.*
           FROM company AS company
           INNER JOIN address AS address_home ON company.address_id_fk = address_home.address_id
           INNER JOIN address AS address_billing ON company.billing_address_id_fk = address_billing.address_id
           INNER JOIN (SELECT  company_id_fk,
                               max(case when company_role_id_fk = '1' then 'true' end) isClient,
                               max(case when company_role_id_fk = '2' then 'true' end) isSupplier
                       FROM company_role_company_maps AS crcm
                       WHERE crcm.company_id_fk = $id
                       GROUP BY company_id_fk) AS T1
           ON(company.company_id = T1.company_id_fk)
           WHERE company.company_id = $id";

    $resultset = $this->getDbAdapter()->query($sql, \Zend\Db\Adapter\Adapter::QUERY_MODE_EXECUTE);
    $current = $resultset->current()->getArrayCopy();

但由于某种原因,当我进行循环时,我得到了错误。

我试着看看我是否抓住了一些东西。

        $sql = "SELECT *
                FROM company";

    $stmt = $this->getDbAdapter()->query($sql, \Zend\Db\Adapter\Adapter::QUERY_MODE_EXECUTE);

    if ($stmt instanceof \Zend\Db\ResultSet\ResultSet) {
        try{
            foreach($stmt as $row) {
                var_dump($row);
            }

        }catch(\Exception $e){
            var_dump($e->getMessage());
        }
    }

但我刚收到内部服务器错误消息(您正在查找的资源存在问题,无法显示。)

0 个答案:

没有答案