Pages

Wednesday, August 22, 2012

Zend framework : Where to write sql queries

Zend Framework provides DbTables i.e for each database table there is an associated DbTable to it. For better understanding please refer to below e.g.

Class Model_DbTable_User extends Zend_Db_Table_Abstract
{
    protected $_name = 'user';

    public function fetchUsers() {

       return $this->select()->from($this->_name)
              ->where('status=?','Active');
   }
}


As you can see from above example, we have to create file named User.php at application/models/DbTable/User.php.

Also note "$_name" where we have to specify the database table name. Here I'm using Zend_Db_Select Object to form SQL queries.

For more information on Db tables and Select Object, please refer to below references:

http://framework.zend.com/manual/en/zend.db.select.html
http://framework.zend.com/manual/en/zend.db.table.html

6D7ZDFF7V2VG

1 comment:

Curran Burke said...

Zend\Db\Sql is a SQL abstraction layer for building platform specific SQL queries via a object-oriented API.