如何在支付操作失败后禁用 Magento 中的 MySQL 查询回滚?
我在 Magento 中编写了一个手动脚本来记录付款流程中的交易。事务成功后,MySQL 查询工作正常,我可以看到 MySQL 中的数据。但是我的查询在付款失败后回滚(看起来像插入和删除)。当我查看 MySQL 表时,我可以看到自动增量增加,但没有数据。
我的代码如下。如何阻止 Magento 回滚我的查询?
$conn = Mage::getSingleton('core/resource')->getConnection('core_write');
$results = $conn->query("insert into pos_transactions(order_id, transaction_time, ip, type) values('$orderId', '$sysDate', '$ip', 'Auth')");
I've coded a manual script in Magento to log my transactions in a payment process. The MySQL query works fine after a successful transaction and I can see the data in MySQL. But my query rollbacks (looks like inserted and deleted) after an unsuccesful payment. When I look into my MySQL table I can see the auto increment increases but no data.
My code is below. How can I block Magento to rollback my query?
$conn = Mage::getSingleton('core/resource')->getConnection('core_write');
$results = $conn->query("insert into pos_transactions(order_id, transaction_time, ip, type) values('$orderId', '$sysDate', '$ip', 'Auth')");
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
这对我有用(在 Magento Enterprise Edition 1.10 中测试):
$inSql = "INSERT INTO my_table(
fieldA
,fieldB
) ";$inSql.= "VALUES('$valueA', '$valueB'); 提交;";
Mage::getSingleton('core/resource')->getConnection('core_write')->query($inSql);
我希望这对你有用。
This works for me (tested in Magento Enterprise Edition 1.10):
$inSql = "INSERT INTO my_table(
fieldA
,fieldB
) ";$inSql.= "VALUES('$valueA', '$valueB'); commit;";
Mage::getSingleton('core/resource')->getConnection('core_write')->query($inSql);
I hope this works for you.
设置表数据库引擎= MYISAM;
因为MYISAM不支持事务提交和回滚功能。
http://en.wikipedia.org/wiki/MyISAM
(MyISAM的主要缺陷是缺乏事务支持。)
set table DB engine = MYISAM;
because transaction commit and rollback feature is not supported by MYISAM.
http://en.wikipedia.org/wiki/MyISAM
( The major deficiency of MyISAM is the absence of transactions support. )
您可以只使用:
而不是
Magento 将创建一个到数据库的新连接,因为您没有使用单例,并且这个新连接不会有任何打开的事务。
You can just use:
instead of
Magento will create a new connection to the database since you're not using the Singleton and this new connection won't have any open transaction.