你必须在做这件事之前开始交易。
因为您必须告诉数据库您要开始交易。
您必须在自动提交(FALSE)后输入:$db->begin_transaction();
;
请阅读文档:mysqli::begin_transaction
附:请记住,不能使用引擎不支持事务的表。因此,如果在添加begin_transaction
语句rollback()
后无效,请检查您的表格引擎是否已将其设置为具有事务支持的引擎。
要检查你的表引擎调用查询在MySQL终端:
SHOW TABLE STATUS FROM database_name_goes_here;
你会得到表的列表中你的数据库定义的引擎。
要在MySQL的终端呼叫查询得到的交易安全引擎,你可以做的名单(发现交易:YES):
mysql> SHOW ENGINES\G
*************************** 1. row ***************************
Engine: PERFORMANCE_SCHEMA
Support: YES
Comment: Performance Schema
Transactions: NO
XA: NO
Savepoints: NO
*************************** 2. row ***************************
Engine: InnoDB
Support: DEFAULT
Comment: Supports transactions, row-level locking, and foreign keys
Transactions: YES
XA: YES
Savepoints: YES
*************************** 3. row ***************************
Engine: MRG_MYISAM
Support: YES
Comment: Collection of identical MyISAM tables
Transactions: NO
XA: NO
Savepoints: NO
*************************** 4. row ***************************
Engine: BLACKHOLE
Support: YES
Comment: /dev/null storage engine (anything you write to it disappears)
Transactions: NO
XA: NO
Savepoints: NO
*************************** 5. row ***************************
Engine: MyISAM
Support: YES
Comment: MyISAM storage engine
Transactions: NO
XA: NO
Savepoints: NO
...
能够提交和回滚,你必须做查询前开始交易 – num8er