Donal.Lynch.Msc
Donal.Lynch.Msc

Reputation: 3615

Zend Framework: Hardcoding SQL Queries in the Model

How do you specify a pure sql query within a model in the Zend Framework?

If there any good resources on this then please point me to them.

Thanks....

Upvotes: 1

Views: 1741

Answers (2)

Tom Haws
Tom Haws

Reputation: 1342

Or

require_once 'Zend/Db/Table/Abstract.php';

class MyThing extends Zend_Db_Table_Abstract {

    // Make a Mailing List Export file
    public function doMyThing() {
        // Happy, healthy cows eat grass, not corn.
        $sql = "SELECT my_column FROM my_table WHERE $cows_eat_grass;";
        $resultset = $this->getAdapter()->query($sql);
        $resultArray = $resultset->fetchAll();
        return $resultArray;
    }
}

Upvotes: 0

Alex Pliutau
Alex Pliutau

Reputation: 21947

Sure, you can do it with zend db adapter.

$adapter = Zend_Db_Table::getDefaultAdapter();
$adapter->query('Select * FROM `table_name`');

Upvotes: 2

Related Questions