1

Here is my query , I want to write it in zend framework inside model.

SHOW COLUMNS FROM  employee WHERE Field = 'status'

2 Answers 2

1

You can always use $this->getAdapter()->query($yourQuery) to execute an arbitrary query on the current database.

Your function would thus look something like this:

public function getByField($fieldName){

$yourQuery=$this->getAdapter()->quoteInto("SHOW COLUMNS FROM  employee WHERE Field = '?'",$fieldname);

$query=$this->getAdapter()->query($yourQuery);

return $this->getAdapter()->fetchAll($query);
}

This should do it quite nicely.

Sign up to request clarification or add additional context in comments.

7 Comments

I get a fatal error Fatal error: Call to undefined method User_Model_DbTable_Employee::quoteInto() . How can i solve this.This is my code function getstatuscolumn() { $fieldname = 'status'; $yourQuery=$this->getDbTable()->quoteInto("SHOW COLUMNS FROM employee WHERE Field = '?'",$fieldname); $query=$this->getDbTable()->query($yourQuery); return $this->getDbTable()->fetchAll($query); }
Don't do getDbTable(), do a getAdapter(). I don't know what getDbTable() is, but i assume that it returns a Zend_Db_Table_Abstract object. What you want is a ` Zend_Db_Adapter_Abstract` object. Try it EXACTLY as I wrote it.
I tried the same as you had given me the code , and I get a fatal error showing "Fatal error: Call to undefined method User_Model_Employee::getAdapter() in ". What you would suggest me to solve this problem . Thank you.
Does your model extend Zend_Db_Table_Abstract ? If so, this should work. If not, your best chance is to save the database connection from initialization. In any case, you should either try using getAdapter() on your database object, or skip it, and do $this->fetchAll().
Yes my model extend zend_db_table_abstract . how could this problem be solved
|
0
   function getstatusColumn()
   {
      $fieldname = 'status';
     $select = $this->getDbTable()->getAdapter()->quoteInto("SHOW COLUMNS FROM employee WHERE Field = ?",$fieldname);
     $select = $this->getDbTable()->getAdapter()->fetchAll($select);
     foreach($select as $result)
     {   
         $r = $result['Type'];
         $enum = substr($r, 6, -2); 
         $values = explode("','", $enum); 

     }
     return $values;

}

This is what I did to get souliton for my question . This I used to display the values in the drop down list.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.