识别MYSQL中的变量

时间:2013-12-15 01:33:35

标签: mysql magento

我正在尝试在我的magento数据库上运行以下代码:

    UPDATE catalog_product_entity_media_gallery AS mg,
    catalog_product_entity_media_gallery_value AS mgv,
    catalog_product_entity_varchar AS ev
SET ev.value = mg.value
WHERE  mg.value_id = mgv.value_id
    AND mg.entity_id = ev.entity_id
    AND ev.attribute_ID = '76'
    AND mgv.position = 1;

在我运行之前,我需要识别ev.attribute_ID ='76'(每次安装时76不同)

我需要用什么来发现我的特定安装中的数字是什么?

(我正在尝试更新我的magento商店中的图像以大量显示。)

2 个答案:

答案 0 :(得分:0)

您可以通过编程方式更新图像。 阅读Marius所写的答案:How to programatically set the base image to the first image in the list

在Magento中使用直接sql查询不是一个好主意......

答案 1 :(得分:0)

您需要了解属性的entity_type_codeattribute_code,才能获得正确的attribute_id特定安装量。

如果你已经知道这些代码,你可以使用这样的代码,例如:

$entity_type_code = 'catalog_product';
$attribute_code = 'name';
$attributeId = Mage::getSingleton('eav/config')
    ->getAttribute($entity_type_code, $attribute_code)
    ->getId();

如何识别attribute_id的代码

如果您只有attribute_id,但不知道在哪里/如何获取该代码,请按以下步骤操作:

如果您查看catalog_product_entity_varchar的表格定义,您会发现attribute_id是指代eav_attribute.attribute_id的外键。

因此,请检查eav.attribute表格以查找包含attribute_id == 76

的记录

找到的记录确实包含您所追求的一般attribute_code值。

如果您确定entity_type_id是所有特定安装的相同,那么您甚至不需要获取entity_type_code并且可以停止这里。只需将找到的记录的entity_type_id作为第一个参数传递给上面的getAttribute()来电。

如果您的特定安装中的entity_type_id 不同,那么您仍需要获取entity_type_code

获取找到的记录的entity_type_id值并在eav_entity_type表中搜索此entity_type_identity_type_id是指向eav_entity_type.entity_type_id的外键) 。找到的记录包含一般entity_type_code的值,对您的所有安装都有效。


话虽如此,出于BC的原因,我总是建议尽可能使用Magento方法。

相关问题