Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114028 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 87313 invoked from network); 12 Apr 2021 12:07:19 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 Apr 2021 12:07:19 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 2D1A31804DD for ; Mon, 12 Apr 2021 05:07:50 -0700 (PDT) X-Spam-Checker-Version: SpamAssassin 3.4.2 (2018-09-13) on php-smtp4.php.net X-Spam-Level: X-Spam-Status: No, score=-2.1 required=5.0 tests=BAYES_00,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,FREEMAIL_FROM,HTML_MESSAGE, RCVD_IN_DNSWL_NONE,RCVD_IN_MSPIKE_H2,SPF_HELO_NONE,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-lf1-f53.google.com (mail-lf1-f53.google.com [209.85.167.53]) (using TLSv1.3 with cipher TLS_AES_256_GCM_SHA384 (256/256 bits) key-exchange ECDHE (P-256) server-signature RSA-PSS (4096 bits) server-digest SHA256) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 12 Apr 2021 05:07:48 -0700 (PDT) Received: by mail-lf1-f53.google.com with SMTP id b14so20969772lfv.8 for ; Mon, 12 Apr 2021 05:07:48 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:from:date:message-id:subject:to; bh=qvSC+w+LPUC615GdljB3PNkGqE+fdezd01djq6AqNVk=; b=Rma/3cWwknDhmRiHxuAr7SpGl3HiSUX+Daq83QzwMyyXJGDYmwoDaublJJZrDIdaF3 5gcam2fZal2M5K7tSFXfWlPh+9c2ETmYsPlgAih7k86/0DY7Quw+h8/MIeldzbsInaLn RZFMgTBG/RWiuXvwFkBu5IehTni0WdWcV2YlHbbHjXjcpnxx5SpAVwei8zRRPk+94UFD h+qICyLjFLXK85jtISF3yb/g7AZ/nxaLppM6M120A66NCHPDqOxcSkhO4fxDVtReDynd 0FLyQhNVSPx/ycER609uZnYyjYw19Q2/nlTFGOaq/BWq08Dl8GFQfTRvh1oVaf3RNccs Fazw== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:from:date:message-id:subject:to; bh=qvSC+w+LPUC615GdljB3PNkGqE+fdezd01djq6AqNVk=; b=ac7A5cp6JzM1/S4qzFzVK1NP45Gbd9xKf1IvYCuPuXfY7cjMrEy/st9BqsEf/Zx66D Q9uJuXMaZCTXRK+DsFwMxxe96TjHgQyf2sSh6o9TrJVJdcr+YmU3tIJwHsAN1ZQP5KKT rYELTAyTzskAehzUBAfOVN+tsOqOSEgS8KvKzgNU9JLPETf1Q7joNyvOWNvJ7opM9jD2 sV7gdMGznEesRE5KN2nTgykizZLhEJKXZJk7t4tNREvkLJlwrv3VbyiP76CVtzx35+nd WH1NBeaTumfVI1jaR6RnwQghJq9dmjbvyxA05o2YIoLqxEgi1jfT5iabZSsB150Heg1X 3ptw== X-Gm-Message-State: AOAM533OVCSRyBE7ZVsv7DvycrpMTzcpex4q7lYABSIeFG821R9wNyey gzsZCn/Xe+0wI7JrSqLpp8MeoIg6vd5KsDepPD974DIwmGkfMw== X-Google-Smtp-Source: ABdhPJyq2CFW20qftZ2eXFxh4pPC/5qxKn/vsjg2P58e+Dx21JWCIqm0QhyuzYZEL4qJB+PDQ97hc7U/cnw8WsDuCy0= X-Received: by 2002:a05:6512:48d:: with SMTP id v13mr13933296lfq.485.1618229266964; Mon, 12 Apr 2021 05:07:46 -0700 (PDT) MIME-Version: 1.0 Date: Mon, 12 Apr 2021 14:07:31 +0200 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="0000000000009f63fe05bfc55c52" Subject: Allow commit() without transaction? From: nikita.ppv@gmail.com (Nikita Popov) --0000000000009f63fe05bfc55c52 Content-Type: text/plain; charset="UTF-8" Hi internals, Since PHP 8.0, PDO fully supports MySQL transactions -- this means that inTransaction() will report the actual connection transaction state, as opposed to an emulated (incorrect) transaction state tracked by PDO itself. This has two primary effects: PDO is aware of transactions created without going through it's APIs (e.g. by manually issuing a START TRANSACTION query) and is aware of implicit commits (see https://dev.mysql.com/doc/refman/8.0/en/implicit-commit.html for more information). The latter means that code like $pdo->beginTransaction() $pdo->exec('DROP TABLE foobar'); // Implicitly commits transaction $pdo->exec('DROP TABLE barfoo'); // Transaction not active anymore $pdo->commit(); // Throws because no transaction active now throws an exception, because commit() is called without an active transaction. It's possible to use if ($pdo->inTransaction()) $pdo->commit(); if you don't care about the lack of active transaction. I believe this behavior is correct, but I could see an argument made in favor of always allowing commit() calls (but not rollBack() calls) even if there is no active transaction. That would change the meaning of commit() from "commit an active transaction" towards "commit if an active transaction exists". Any opinions on that? Regards, Nikita --0000000000009f63fe05bfc55c52--