你必須在做這件事之前開始交易。
因爲您必須告訴數據庫您要開始交易。
您必須在自動提交(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