试试这个:
$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
您不应在Magento中编写任何自定义查询,请改用模型。 – OSdave 2012-08-03 11:06:45