2011-12-13 39 views
0

我想在我的模型類中使用select查詢而沒有實例化Zend_Db :: factory(),因爲我在application.ini.My中給出了數據庫的所有參數,數據庫名是mst2。 我的模型類,如下所示:在Zend項目的任何地方使用select查詢

class Application_Model_EmpIdMapper extends Zend_Db_Table_Abstract 
{ 

    public function checkEmpid($empId) 
    { 
      $select=$this->select() 
         ->from(array('tc' => 'tcs_contact'),array('tc.employee_id')); 
      $table_data=$this->fetchAll($select); 
      $table_data=$table_data->toArray(); 
      foreach($table_data as $row) 
      { 

        // don check the condition before putting it into for each loop 
       if($row['employee_id'] == $empId) 
       { 
        return 'true'; 
       } 
       else 
       { 
        return 'false'; 
       } 

      } 

      } 


     } 

但ruuning應用程序給出了錯誤作爲

SQLSTATE [42S02]:基表或視圖未找到:1146表 'mst2.application_model_empidmapper' 沒有按不存在。

如何解決此問題?

+0

什麼是數據庫中的表名? – emaillenin

回答

0

以下內容添加到您的模型類:

// the actual name of the table in the database 
protected $_name = 'the_name_of_your_Table_you_want_to_use'; 
+0

我不想在模型類中指定特定的表名,因爲我必須使用join在多個表上執行操作。在那種情況下應該做什麼? – ryan

+0

我認爲這根本不是問題。如果我沒有完全錯誤,你必須調用$ select-> setIntegrityCheck(false);在多個表上執行連接(http://framework.zend.com/manual/en/zend.db.table.html#zend.db.table.advanced.usage示例27)。 – mychiara