如何使用Zend_Db_Table_Abstract类执行查询?

时间:2014-11-10 09:44:35

标签: php zend-framework

这是我在zend中的代码。我尝试在函数getALaCarte()中执行查询并将其作为数组返回。但是var_dump($ smth)的结果是空的。为什么?

<?php

namespace Application\Model\DbTable;

use Application\Model\Interfaces\ActiveEntity;

class Categories extends \Zend_Db_Table_Abstract implements ActiveEntity
{
    protected $_name     = 'categories';
    protected $_primary  = 'id';
    protected $_rowClass = 'Application\Model\Object\Category';
    protected $_referenceMap = array(
        'xml' => array(
            'columns'       => 'xml_id',
            'refTableClass' => 'Application\Model\DbTable\ProductXml',
            'refColumns'    => 'id',
        ),
    );    

    /**
     * Returns params for Zend_Db_Table_Select for fetching active categories.
     *
     * @return Zend_Db_Table_Select
     */
    public function getActiveParams()
    {
        return $this->select()->where('`is_active` = 1');
    } 

    public function getALaCarte(){

        $db = new Zend_Db_Table_Select('categories');
        $stmt = $db->query("SELECT * from categories c inner join xml_products x on x.id = c.xml_id where is_alacarte = '1'");
        var_dump($stmt);
        exit();
    }   
}

1 个答案:

答案 0 :(得分:0)

尝试这种方式:

$stmt = $db->query("SELECT * from categories c inner join xml_products x on x.id = c.xml_id where is_alacarte = '1'");
$select = $db->query($stmt);
$result = $select->execute();
var_dump($result);