I've coded a manual script 开发者_Python百科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')");
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.
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. )
You can just use:
$conn = Mage::getModel('core/resource')->getConnection('core_write');
instead of
$conn = Mage::getSingleton('core/resource')->getConnection('core_write');
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.
精彩评论