How to do custom query in magento?

后端 未结 1 1218
迷失自我
迷失自我 2021-02-06 07:32

I want to write a custom query in magento website.

I created a file test.php in my magento root folder & written a custom query



        
1条回答
  •  南笙
    南笙 (楼主)
    2021-02-06 07:48

    Try this:

    $connection = Mage::getSingleton('core/resource')->getConnection('core_read');
    $sql        = "Select * from catalog_product_flat_1";
    $rows       = $connection->fetchAll($sql); //fetchRow($sql), fetchOne($sql),...
    Zend_Debug::dump($rows);
    

    In order to test, you can create sandbox.php file in root of your magento installation and paste the following code:

    getConnection('core_read');
    $sql        = "Select * from catalog_product_flat_1";
    $rows       = $connection->fetchAll($sql); //fetchRow($sql), fetchOne($sql),...
    Zend_Debug::dump($rows);
    

    and call from url as:

    http://your-magento-url/sandbox.php
    

    0 讨论(0)
提交回复
热议问题