magento - 如何在 magento 中进行自定义查询?

标签 magento

我想在 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/

相关文章:

php - 位置排序不适用于产品列表页面 magento2

magento - 更改 Magento 产品页面上的文本 "Choose an option..."

magento - 以编程方式将 Magento 产品添加到类别

magento - Paypal Checkin Tab 过期

ruby-on-rails - rails - 在 magento api REST 上请求 token

Magento 1.7 : "Place Order" disabled by default in PayPal Express Review

xml - 如何将 Magento 页面标题移动到侧边栏上方

magento - getCollection() 在前端返回 1 个值,在后端返回多个值

magento - Magento 安装中出现重复的 PHP 文件?

magento - 在 magento 中发送邮件