Use adapter with Zend_Db

Description:

Return a selection of database table fields using the Zend_Db adapter with Zend Framework

Solution

It’s easier to create an adapter of the database table class and use it in returning the desired values. This grants speed, clean code and accuracy.

Example:

$customersTable = new DbTable_CustomersTable;
$adapter = $customersTable ->getAdapter();
$select = $adapter->select();
$select->from(array(‘cu’ => $customersTable ->getName()), 
array(DbTable_CustomerRow::CUSTOMER_NAME));
$select->where(
‘cu.’. DbTable_CustomerRow::EMAIL .’ LIKE “admin%”‘);

return $result = $adapter->fetchAll($select);

The example loads the Customers table class and runs the select of the Customer_name fields that match the “admin” email address.

Advertisements

About admin

Just another php developer trying to give something back to the community.
This entry was posted in Best practices, SQL, Zend Framework and tagged , , . Bookmark the permalink.

Leave a Reply

Fill in your details below or click an icon to log in:

WordPress.com Logo

You are commenting using your WordPress.com account. Log Out / Change )

Twitter picture

You are commenting using your Twitter account. Log Out / Change )

Facebook photo

You are commenting using your Facebook account. Log Out / Change )

Google+ photo

You are commenting using your Google+ account. Log Out / Change )

Connecting to %s