7

Magento Web サイトでカスタム クエリを作成したいと考えています。

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>";
?>

しかし、それは私に何の結果も与えていません。私を導いてください。

4

1 に答える 1

22

Try this:

$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);

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);

and call from url as:

http://your-magento-url/sandbox.php
于 2012-08-03T09:20:11.890 に答える