Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114041 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 30516 invoked from network); 12 Apr 2021 18:16:14 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 Apr 2021 18:16:14 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id ABE3F1804DA for ; Mon, 12 Apr 2021 11:16:46 -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_H3,RCVD_IN_MSPIKE_WL,SPF_HELO_NONE, SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from mail-ot1-f48.google.com (mail-ot1-f48.google.com [209.85.210.48]) (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 11:16:43 -0700 (PDT) Received: by mail-ot1-f48.google.com with SMTP id w21-20020a9d63950000b02901ce7b8c45b4so13673875otk.5 for ; Mon, 12 Apr 2021 11:16:43 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20161025; h=mime-version:references:in-reply-to:from:date:message-id:subject:to; bh=JAAwxrLceI+4ctTcE4zmYkfJj/rKmdnV8gMB2SQBCPw=; b=jOksgQZsYsWL2nE7GMryCfZh86P3o784/rdBmnKkjD9muWcJWByglJ8kvZZUunkGd+ Eph0vkNjKTPwgqljWcIfbhTTLjBLoBERNQYpyyjODn2/vwXgWvgFYThjAylgPPr8+7G9 nySXB9Y+0i2M4Bc7pzzGYUDUG45glodyyfbbgx0RcGTyh/4Pf/VJI6FtLsy6Bkqdt0C4 SD303pPkPjKdM+OVoyGLmsTsBDY4qAizYcwjy9yv1c0FLoC6KXCt7Vm3p8LT5QbXoIyt YhPim4mbE+PHQor9z6UsB8HiWl0MZ2bIrqaI8a9SB0PImDfvfx5uDEfmlLJbrgkW8Kcp kIGQ== X-Google-DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=1e100.net; s=20161025; h=x-gm-message-state:mime-version:references:in-reply-to:from:date :message-id:subject:to; bh=JAAwxrLceI+4ctTcE4zmYkfJj/rKmdnV8gMB2SQBCPw=; b=V9APV/cYr/FDW7S17ZBbtGY1y90vtlnTQJjdifsXb8WHL11D1to+1Vrw6tETTSb269 myAnVFbZIgb2ptL+txelIdKASsqnzOjVJeKCnpgKR13dGBbuvx2MLZOM8VZhvZMTXgdL Hi0mZ0YCCSHEb/LZAQR6oJs6i3/v7mqgsxV/cdK1A8dM0+Sknb5DjcYptYiJHh909ZEz qOJ1IzM2Rhbb8sHQFr4EG0wZ9EF2V0LkqIPTp4n257oYS3r6PLG3Kweb1+0FjczfVhoS eBRGc+ur3vrgo07Kr1uhwcpDxZo7RXJ/yLYJEKJgR2kBXRwNtKp0wPTF5fB0a0hXbR9f X7Sw== X-Gm-Message-State: AOAM532mOyaMPsddHTTYqRtxVZ2gKnffnzafdbZc+zi2P66a3UHQOoac JBf2aEsggqc0taKIAoa7R+eraQbtRIeIOajQUs7mBS04RaE= X-Google-Smtp-Source: ABdhPJwh+AAVw/PdfDElN4BUrOqsC6IE4tbMFF8zcOfvsI9/U3NoX63ABzoSFToNuwSkJjLkgs98QUsantxeQvxlCrw= X-Received: by 2002:a9d:de5:: with SMTP id 92mr17893344ots.25.1618251402367; Mon, 12 Apr 2021 11:16:42 -0700 (PDT) MIME-Version: 1.0 References: In-Reply-To: Date: Mon, 12 Apr 2021 19:16:32 +0100 Message-ID: To: PHP internals Content-Type: multipart/alternative; boundary="000000000000fed54d05bfca8315" Subject: Re: [PHP-DEV] Allow commit() without transaction? From: davidgebler@gmail.com (David Gebler) --000000000000fed54d05bfca8315 Content-Type: text/plain; charset="UTF-8" Good example of why commit() should throw an exception, I think - it's just alerted the developer that executing their previous statement has caused an implicit commit. Imagine if they had a complex sequence of queries and didn't realise they'd added one which ended the transaction, thinking they could safely rollback later if necessary. The exception catches this early on. Regards, David Gebler On Mon, Apr 12, 2021 at 1:07 PM Nikita Popov wrote: > 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 > --000000000000fed54d05bfca8315--