Querying a mysql database table view in Zend Framework

后端 未结 1 1022
失恋的感觉
失恋的感觉 2021-01-29 09:11

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条回答
  • 2021-01-29 09:35

    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);
    
    0 讨论(0)
提交回复
热议问题