我想写在Magento的网站自定义查询。
我在Magento的根文件夹中创建的文件test.php的和书面的自定义查询
<?php
$read= Mage::getSingleton('core/resource')->getConnection('core_read');
$value=$read->query("Select * from catalog_product_flat_1");
$row = $value->fetch();
echo "<pre>";print_r($row);echo "</pre>";
?>
但它不给我任何results.Please指导我。
试试这个:
$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);
从网址拨打:
http://your-magento-url/sandbox.php