gpt4 book ai didi

php - MySQL 中的 MySQL Transaction+ PHP 问题

转载 作者:行者123 更新时间:2023-11-29 05:43:15 25 4
gpt4 key购买 nike

我有一个代码在我遇到回滚问题的应用程序中使用。即使我 's2' 返回错误回滚也不会发生,即表 'products' 正在被删除。任何人都可以解释为什么它不起作用或我应该如何更改它。注意:表是 Innodb 引擎的..我用的是 mysql 5.0+

    mysql_query('SET AUTOCOMMIT=0;');
mysql_query('START TRANSACTION;');
$sql = 'DROP TABLE '.$this->Product->tablePrefix.'products';
$s1 = mysql_query($sql);
$sql = 'RENAME TABLE '.$this->Product->tablePrefix.'temp12212 TO '.$this->Product->tablePrefix.'products';
$s2 =mysql_query($sql);
if($s1 && $s2){
mysql_query('COMMIT;');
$this->Session->setFlash('Commit Successful to Database');
}else{
mysql_query('ROLLBACK;');
$this->Session->setFlash('Commit failed due to some errors<br> auto-rollbacked to previous state');
}

最佳答案

DROP TABLE 是 MySql 中导致隐式提交的命令之一。

http://dev.mysql.com/doc/refman/5.1/en/implicit-commit.html

改用这个:

'RENAME TABLE '.$this->Product->tablePrefix.'products TO backup_table
, '.$this->Product->tablePrefix.'temp12212 TO '.$this->Product->tablePrefix.'products';

关于php - MySQL 中的 MySQL Transaction+ PHP 问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/4790545/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com