In WordPress, you can use $wpdb->query('COMMIT') Submit the transaction.
In your code, you can call this function after all SQL operations have been completed. $wpdb->query('COMMIT') Submit a transaction. If an error occurs during execution, you can use it. $wpdb->query('ROLLBACK') Rollback a transaction. For example:
global $wpdb;
$table_name = $wpdb->prefix . 'my_table';
$wpdb->query('START TRANSACTION');
// 执行 SQL 操作
// ...
// 如果没有错误,提交事务
$wpdb->query('COMMIT');
// 如果发生错误,回滚事务
$wpdb->query('ROLLBACK');here START TRANSACTION Indicates the initiation of a new transaction.COMMIT Indicates submission of a transaction.ROLLBACK Indicates rolling back a transaction. If an error occurs during execution, this can be used. ROLLBACK Roll back the transaction and undo all operations.