magento-自定义查询

magento-自定义查询,magento,Magento,当我在Magento中使用下面的代码进行自定义查询时,它工作得很好 $connection = Mage::getSingleton('core/resource')->getConnection('core_read'); $sql = 'SELECT * FROM sales_order_custom'; $rows = $connection->fetchAll($sql); 但是当我改变的时候 $sql = 'SEL

当我在Magento中使用下面的代码进行自定义查询时,它工作得很好

 $connection = Mage::getSingleton('core/resource')->getConnection('core_read');
    $sql        = 'SELECT * FROM sales_order_custom';
    $rows       = $connection->fetchAll($sql);
但是当我改变的时候

$sql        = 'SELECT * FROM sales_order_custom WHERE key = "catalog_code"';

它给出的结果是空的。

尝试使用$sql=SELECT*FROM sales\u order\u custom其中的'key`=“catalog\u code”

与您的查询类似的查询非常有效

$connection = Mage::getSingleton('core/resource')->getConnection('core_read');
$sql = "SELECT * FROM cms_page WHERE title='About  Us'";
$rows = $connection->fetchAll($sql);
var_dump($rows);
die();
不管怎样,最好使用类似的方式,但这是另一回事:

$connection->select()->from(.....

查询以获取magento中的客户完整记录。。 姓名、地址、密码、电子邮件、联系电话

 SELECT concat((SELECT `value` FROM `customer_entity_varchar` WHERE `attribute_id`=5 AND `entity_id`= '$pup_owner'),' ', (SELECT `value` FROM `customer_entity_varchar` WHERE `attribute_id`=7 AND `entity_id`= '$pup_owner')) as `owner_name`,

 concat((SELECT `value` FROM `customer_address_entity_text` WHERE `entity_id`= (select `value` FROM `customer_entity_int` WHERE `entity_id`='$pup_owner' AND `attribute_id`=14)), ',',(SELECT `value` FROM `customer_address_entity_varchar` WHERE `attribute_id`=26 AND `entity_id`= (select `value` FROM `customer_entity_int` WHERE `entity_id`='$pup_owner' AND `attribute_id`=14)),',' ,(SELECT `value` FROM `customer_address_entity_varchar` WHERE `attribute_id`=28 AND `entity_id`= (select `value` FROM `customer_entity_int` WHERE `entity_id`='$pup_owner' AND `attribute_id`=14))) as `owner_address`,

 concat((SELECT `value` FROM `customer_address_entity_varchar` WHERE `attribute_id`=30 AND `entity_id`= (select `value` FROM `customer_entity_int` WHERE `entity_id`='$pup_owner' AND `attribute_id`=14)),'') as `owner_pincode` ,

 concat((SELECT `email` FROM `customer_entity` WHERE `entity_id`= '$pup_owner'),'') as `owner_email` ,

 concat((SELECT `value` FROM `customer_address_entity_varchar` WHERE `attribute_id`=31 AND `entity_id`= (select `value` FROM `customer_entity_int` WHERE `entity_id`='$pup_owner' AND `attribute_id`=14)),'') as `owner_contact`

两者都是不同的查询。一个是简单选择查询,另一个是条件查询。你想干什么?