Querying a mysql database table view in Zend Frame

2019-03-03 16:56发布

问题:

My question is straight forward. How do I query a mysql view table in Zend Framework since technically a view is not a table.

回答1:

You can query it the same way you would a normal table using Zend_Db directly, or using Zend_Db_Table.

The following work for me:

$db = Zend_Db_Table::getDefaultAdapter();

$select = $db->select()
             ->from('view_not_table')
             ->where('id > ?', 64);

$results = $select->query()->fetchAll();

// or, setting up a Zend_Db_Table

class Application_Model_DbTable_ViewNotTable extends Zend_Db_Table_Abstract
{
    protected $_name     = 'view_not_table';
    protected $_primary  = 'id';
    protected $_sequence = false;
}

$table = new Application_Model_DbTable_ViewNotTable();
$table->fetchAll();
$table->select()
      ->from($table)
      ->where('id = ?', $id);