Search code examples
phpmysqlzend-frameworkzend-db

Use select query anywhere in the project in zend


I want to use select query in my model class without instantiating Zend_Db::factory() because I have given all the parameters of database in application.ini.My database name is mst2. My model class is as follows:

 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';
                 }

             } 

           } 


        }

but ruuning the application gives the error as

SQLSTATE[42S02]: Base table or view not found: 1146 Table 'mst2.application_model_empidmapper' doesn't exist.

How to resolve this issue?


Solution

  • Add the following to your Model class:

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