我想在 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>";
?>
但它没有给我任何结果。请指导我。
最佳答案
尝试这个:
$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 - 如何在 magento 中进行自定义查询?,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/11792762/