Php 带有嵌套select语句的MySQL触发器
我在magento数据库中的触发器语法方面遇到了一些困难 我想在创建新地址时更新customer表中的值 customer\u address\u entity\u varchar表如下所示:Php 带有嵌套select语句的MySQL触发器,php,mysql,magento,triggers,Php,Mysql,Magento,Triggers,我在magento数据库中的触发器语法方面遇到了一些困难 我想在创建新地址时更新customer表中的值 customer\u address\u entity\u varchar表如下所示: value_id | entity_type_id | attribute_id | entity_id | value 48 | 2 | 28 | 3 | Lancashire 当我在没有嵌套select语句的情况下执行触发器时
value_id | entity_type_id | attribute_id | entity_id | value
48 | 2 | 28 | 3 | Lancashire
当我在没有嵌套select语句的情况下执行触发器时,它会工作,因此:
IF (new.attribute_id=28) THEN
UPDATE customer_entity SET customer_entity.group_id = 4
WHERE customer_entity.entity_id = 1
END IF;
我尝试使用new.entity_id和new.value从其他表中选择值来替换4和1:
DROP TRIGGER IF EXISTS `groupid_update`;
CREATE DEFINER=`rock_store`@`localhost` TRIGGER `groupid_update`
AFTER INSERT ON `customer_address_entity_varchar`
FOR EACH ROW
IF (new.attribute_id = 28) THEN
UPDATE customer_entity
SET customer_entity.group_id = (
SELECT directory_country_region_name.customer_group_id
FROM directory_country_region_name
WHERE directory_country_region_name.name = "'" + new.value + "'")
WHERE customer_entity.entity_id = (
SELECT customer_address_entity.parent_id
FROM customer_address_entity
WHERE customer_address_entity.entity_id = new.entity_id);
END IF;
在MySQL中创建触发器是成功的,但是当我尝试在Magento中添加一个新地址时,我得到了一个错误,它没有告诉我什么
谢谢你的帮助。利亚姆我设法解决了这个问题,打破了我试图做的事情
IF (new.attribute_id = 28) THEN
SET @add_entity_id = new.entity_id;
SET @county = new.value;
SET @group_id = (SELECT directory_country_region_name.customer_group_id
FROM directory_country_region_name
WHERE directory_country_region_name.name = @county);
SET @customer_id = (
SELECT customer_address_entity.parent_id
FROM customer_address_entity
WHERE customer_address_entity.entity_id = new.entity_id);
UPDATE customer_entity SET customer_entity.group_id = @group_id WHERE customer_entity.entity_id = @customer_id;
END IF