magento - 自定义查询

时间:2013-06-11 13:39:48

标签: magento

当我在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"';

它给出空的结果。

3 个答案:

答案 0 :(得分:0)

尝试使用$ sql = SELECT * FROM sales_order_custom WHERE`key` =“catalog_code”'

答案 1 :(得分:0)

对你的类似查询就像魅力......

$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(.....

答案 2 :(得分:0)

查询以获取客户在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`