Magento

Magento execute custom query

  • 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);

    $optionsCollection->getSelect()->join(
    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’);

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