Thursday, December 1, 2011

Magento uses Zend to prepare query

As Many people are confuse with the database query. Just have a look how the Magento uses zend to run the query
As you have notice that ResourceModel files in Magento doesnot uses the Plain my sql.They are using(prpearing) from the Zend_Db.This means that Magento is using Zend for handling requests.

$read = Mage::getSingleton('core/resource')->getConnection('core_read');
echo get_class($read);


You will get the class as Varien_Db_Adapter_Pdo_Mysql which is an extension of Zend_Db_Adapter Abstract. You can create an instance of a Zend_Db_Select object using the select() method of a Zend_Db_Adapter_Abstract object. This can be used to build ‘SELECT’ queries. When building the query, you can add clauses of the query one by one. There is a separate method to add each clause to the Zend_Db_Select object. For example:


To Build this query:
“SELECT product_id, product_name, price FROM “products” WHERE price > 100.00″ //this is not a magento query


We can write:
$select = $read->select()->from(‘products’, array(‘product_id’, ‘product_name’, ‘price’))->where(‘price > 100.00′);

No comments:

Post a Comment

Thankyou for your Comments

LinkWithin

Blog has moved, searching new blog...