【发布时间】:2010-06-01 22:02:00
【问题描述】:
我正在为 Magento 开发一个新的支付模块,但遇到了一个我无法解释的问题。以下代码在信用卡验证后运行:
$table_prefix = Mage::getConfig()->getTablePrefix();
$tableName = $table_prefix.'authorizecim_magento_id_link';
$resource = Mage::getSingleton('core/resource');
$writeconnection = $resource->getConnection('core_write');
$acPI = $this->_an_customerProfileId;
$acAI = $this->_an_customerAddressId;
$acPPI = $this->_an_customerPaymentProfileId;
$sql = "insert into {$tableName} values ('', '$customerId', '$acPI', '$acPI', '3')";
$writeconnection->query($sql);
$sql = "insert into {$tableName} (magCID, anCID, anOID, anObjectType) values ('$customerId', '$acPI', '$acAI', '2')";
$writeconnection->query($sql);
$sql = "insert into {$tableName} (magCID, anCID, anOID, anObjectType) values ('$customerId', '$acPI', '$acPPI', '1')";
$writeconnection->query($sql);
我已经使用 Firebug 和 FirePHP 验证了 SQL 查询在语法上是正确的,并且没有返回任何错误。
这里奇怪的是我已经检查了数据库,并且每次运行代码时都会增加自动增量值。但是,不会在数据库中插入任何行。我已经通过在第一次写入后直接添加die(); 语句来验证这一点。
任何想法为什么会发生这种情况?
config.xml 的相对部分是这样的:
<config>
<global>
<models>
<authorizecim>
<class>CPAP_AuthorizeCim_Model</class>
</authorizecim>
<authorizecim_mysql4>
<class>CPAP_AuthorizeCim_Model_Mysql4</class>
<entities>
<anlink>
<table>authorizecim_magento_id_link</table>
</anlink>
</entities>
<entities>
<antypes>
<table>authorizecim_magento_types</table>
</antypes>
</entities>
</authorizecim_mysql4>
</models>
<resources>
<authorizecim_setup>
<setup>
<module>CPAP_AuthorizeCim</module>
<class>CPAP_AuthorizeCim_Model_Resource_Mysql4_Setup</class>
</setup>
<connection>
<use>core_setup</use>
</connection>
</authorizecim_setup>
<authorizecim_write>
<connection>
<use>core_write</use>
</connection>
</authorizecim_write>
<authorizecim_read>
<connection>
<use>core_read</use>
</connection>
</authorizecim_read>
</resources>
</global>
</config>
编辑: 按原样创建表的查询是:
CREATE TABLE `mag_authorizecim_magento_id_link` (
`link_id` INT(11) NOT NULL AUTO_INCREMENT,
`magCID` INT(11) NOT NULL,
`anCID` INT(11) NOT NULL,
`anOID` INT(11) NOT NULL,
`anObjectType` INT(11) NOT NULL,
PRIMARY KEY (`link_id`)
) ENGINE=INNODB AUTO_INCREMENT=44 DEFAULT CHARSET=utf8
【问题讨论】:
-
请同时发布表格定义...
-
@Zak:感谢您的快速回复。表格def已发布。