如何在magento中进行自定义查询? [英] How to do custom query in magento?
本文介绍了如何在magento中进行自定义查询?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想在magento网站上编写自定义查询.
I want to write a custom query in magento website.
我在magento根文件夹&中创建了文件test.php.编写了一个自定义查询
I created a file test.php in my magento root folder & written a custom query
<?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>";
?>
但是它没有给我任何结果.请指导我.
But it is not giving me any results.Please guide me.
推荐答案
尝试一下:
$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文件,并粘贴以下代码:
In order to test, you can create sandbox.php file in root of your magento installation and paste the following code:
<?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中进行自定义查询?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文