试试这个:
$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);
为了进行测试,您可以在您的 magento 安装的根目录中创建 sandbox.php 文件并粘贴以下代码:
<?php
$mageFilename = 'app/Mage.php';
require_once $mageFilename;
Mage::setIsDeveloperMode(true);
ini_set('display_errors', 1);
umask(0);
Mage::app();
$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);
并从 url 调用:
http://your-magento-url/sandbox.php