我快要拔头发了...为什么不能运行?
Mage::getSingleton('core/resource')->getConnection('core_write')->query('DELETE FROM catalog_product_super_attribute WHERE product_id = 46');
当我通过命令行甚至 phpmyadmin 运行该查询时,它执行得很好,删除了所有行但是当我尝试使用代码运行它时它不起作用。我什至尝试过绕过 Magento,希望它对他们有用,但是当我尝试在 php 中使用直接 mysql 或 mysqli 删除时,它也不起作用。
任何想法或建议都会很棒。
最佳答案
$transaction = Mage::getSingleton('core/resource')->getConnection('core_write');
try {
$transaction->beginTransaction();
$transaction->query('DELETE FROM catalog_product_super_attribute WHERE product_id = 46');
$transaction->commit();
} catch (Exception $e) {
$transaction->rollBack(); // if anything goes wrong, this will undo all changes you made to your database
}
关于mysql - 原始删除查询,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/21269703/