我正在为Magento设计一个新的付款模块,并且遇到了一个我无法解释的问题。该信用卡后运行下面的代码进行验证:Magento - 数据未插入数据库,但ID是自动增加的
$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
请张贴表def ...... – Zak 2010-06-01 22:05:46
@Zak:感谢您的快速响应。表def已发布。 – Joseph 2010-06-01 22:12:36