我正在创建一个自定义模块,但它没有在表中插入数据。虽然它显示“成功”消息 这里我的 observe.php 代码是:
$write1 = Mage::getSingleton("core/resource")->getConnection("core_write");
//$query_meter = "insert into catalog_customer_product_meterreading (customer_id, product_id,meter_key ) values ($cutomer_id, $product_id,'$serial_key')";
$query_meter = "INSERT INTO `catalog_customer_product_meterreading` (`customer_id`, `product_id`, `meter_key`) VALUES ('2', '2', '334')";
// print_r($write1) ;
if($write1->query($query_meter)){
echo "Data successfully inserted.";
}
我的自定义表是:
CREATE TABLE IF NOT EXISTS `catalog_customer_product_meterreading` (
`customer_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Customer ID',
`product_id` int(10) unsigned NOT NULL DEFAULT '0' COMMENT 'Product ID',
`meter_key` varchar(100) NOT NULL COMMENT 'Meter Reading with #',
PRIMARY KEY (`customer_id`,`product_id`,`meter_key`),
KEY `IDX_CATALOG_CATEGORY_PRODUCT_PRODUCT_ID` (`product_id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8 COMMENT='Meter Reading To Catalog Product Table';
ALTER TABLE `catalog_customer_product_meterreading`
ADD CONSTRAINT `catalog_customer_product_meterreading_ibfk_2` FOREIGN KEY (`customer_id`) REFERENCES `customer_entity` (`entity_id`)ON DELETE CASCADE ON UPDATE CASCADE,
ADD CONSTRAINT `catalog_customer_product_meterreading_ibfk_1` FOREIGN KEY (`product_id`) REFERENCES `catalog_product_entity` (`entity_id`)ON DELETE CASCADE ON UPDATE CASCADE;
请建议我我的代码在哪里出错。如果我直接在数据库中复制/粘贴查询,它运行良好。
提前致谢