如何做到自定义查询在Magento?(How to do custom query in magen

2019-07-30 18:42发布

我想写在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指导我。

Answer 1:

试试这个:

$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


文章来源: How to do custom query in magento?
标签: magento