一旦达到
DB::commit
,就会抛出错误。但是,如果我注释掉 Schema::table
代码,它可以在 PHP 8.3 中运行。在 PHP 7.3 中,它仍然按预期工作。
try {
DB::beginTransaction();
if(!empty($table)){
Schema::table($table, function (Blueprint $table) use ($newProfileField) {
$column_type = isset($newProfileField->fieldType) ? $newProfileField- >fieldType->sql_column_type : 'string';
$table->$column_type($newProfileField->field_name)->nullable();
});
}
}
DB::commit();
}
catch(Exception $ex) {
DB::rollback();
}
当我将 PHP 版本升级到 8.3 时,就会发生这种情况
PDO异常。没有活跃交易。
这至少应该解决交易问题:
if (! empty($table)) {
DB::beginTransaction();
try {
DB::table($table)... // extend this line as required.
DB::commit();
} catch (Exception $e) {
DB::rollBack();
}
}