【问题标题】:Why did the transaction that contained DDL statement throw an exception?为什么包含 DDL 语句的事务会抛出异常?
【发布时间】:2021-03-17 18:57:38
【问题描述】:

例如

$conn = new PDO("mysql:host=127.0.0.1;dbname=test", 'root', '123456');
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$conn->beginTransaction();
try {
    $sql = "CREATE TABLE IF NOT EXISTS test2 (
  `id` bigint(20) UNSIGNED NOT NULL AUTO_INCREMENT,
  `text` varchar(32) NOT NULL DEFAULT '',
  PRIMARY KEY (`id`)
) ENGINE=InnoDB DEFAULT CHARSET=utf8mb4;";
    $conn->exec($sql);
    $conn->commit();
} catch (\Exception $e) {
    $conn->rollBack();
}

它在 PHP 7.4 中运行良好,但在 PHP 8.0 中无法运行,并在 $conn->commit(); 行抛出异常:

PDOException: 没有活动的事务

【问题讨论】:

    标签: php mysql pdo transactions php-8


    【解决方案1】:
    猜你喜欢
    • 2012-01-09
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2021-04-28
    • 2013-09-04
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多