2012-08-03 10 views
7

मैं Magento वेबसाइट में एक कस्टम क्वेरी लिखना चाहता हूँ।Magento में कस्टम क्वेरी कैसे करें?

मैं अपने Magento रूट फ़ोल्डर & एक कस्टम क्वेरी

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

लिखा में एक फ़ाइल test.php बनाया लेकिन यह मुझे न जताए किसी भी results.Please मेरे गाइड।

+1

आपको Magento में कोई कस्टम क्वेरी नहीं लिखनी चाहिए, इसके बजाय मॉडल का उपयोग करें। – OSdave

उत्तर

18

इस प्रयास करें:

$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 
+0

यह कुछ भी प्रदर्शित नहीं कर रहा है। – David

+0

यह काम करना चाहिए। प्रयास {} पकड़ {} ब्लॉक के भीतर अपना कोड लपेटने और डेवलपर मोड चालू करने का प्रयास करें। – MagePsycho

+0

आपको बहुत धन्यवाद MagePsycho !! – David

संबंधित मुद्दे