Home » Magento » Magento execute custom query

Magento execute custom query

How to magento execute custom query?In here you can execute custom query to insert,update,delete and fetch data from database with using magento existing database connection.

Magento execute custom query to insert data

Execute custom query to fetch data

Getting data into phtml files/view files



Execute custom query to update data


Similar posts

  • This is the exactly those which i was looking for from many times. I had some doubt on magento query and after reading your post, my doubt was cleared.

    • Thanks for your comment.It’s nice to hear it was success.
      Good luck!

  • I follow above the steps to insert custom query to existing database connections. It’s really helpful to me. Thanks for the informative post.

    • Thanks for your comment.It’s nice to hear that was success.

      Thanks again

  • President Joyce Banda

    very nice tutorial thanks

  • Tat

    Your examples are out of context. Anyway, have to say, it is wrong to use plain queries in Magento. You have to use magento adapter for that. And if you want to write a simple SELECT you should write, e.g:

    $optionsCollection = Mage::getModel(‘catalog/product_option’)->getCollection()
    ->addFieldToFilter(‘product_id’, $productId);

    array(‘title’ => Mage::getSingleton(‘core/resource’)->getTableName(‘catalog/product_option_title’)),
    ‘main_table.option_id = title.option_id’,
    array(‘title’ => ‘title.title’)
    )->where(‘title.store_id = 0’);

    array(‘eq’ => ‘some title’),
    array(‘like’ => ‘%item%’)
    And then you can use $optionsCollection as array inside foreach(){}.