Newsgroups: php.internals Path: news.php.net Xref: news.php.net php.internals:114029 Return-Path: Delivered-To: mailing list internals@lists.php.net Received: (qmail 89360 invoked from network); 12 Apr 2021 12:13:15 -0000 Received: from unknown (HELO php-smtp4.php.net) (45.112.84.5) by pb1.pair.com with SMTP; 12 Apr 2021 12:13:15 -0000 Received: from php-smtp4.php.net (localhost [127.0.0.1]) by php-smtp4.php.net (Postfix) with ESMTP id 389DA1804DD for ; Mon, 12 Apr 2021 05:13: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=-0.7 required=5.0 tests=BAYES_05,DKIM_SIGNED, DKIM_VALID,DKIM_VALID_AU,DKIM_VALID_EF,SPF_HELO_PASS,SPF_PASS autolearn=no autolearn_force=no version=3.4.2 X-Spam-Virus: No X-Envelope-From: Received: from box.beccati.com (box.beccati.com [176.9.123.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (No client certificate requested) by php-smtp4.php.net (Postfix) with ESMTPS for ; Mon, 12 Apr 2021 05:13:45 -0700 (PDT) Received: from authenticated-user (box.beccati.com [176.9.123.236]) (using TLSv1.2 with cipher ECDHE-RSA-AES128-GCM-SHA256 (128/128 bits)) (No client certificate requested) by box.beccati.com (Postfix) with ESMTPSA id D5DEF200300; Mon, 12 Apr 2021 14:13:43 +0200 (CEST) DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=beccati.com; s=mail; t=1618229623; bh=U2e2WXhYiZY5FKTydEnKMaCHKdfXJVLQDlCjMYglGZ8=; h=Date:Subject:To:References:From:In-Reply-To:From; b=V8aenF0cG6K4irl14JsiMuT0wfxk2YKXaD1EW6Z8RnYhOLW8zXlqBbglhzg9i+Xst 0KMDVedVGQOJnyPT5I+MMDeTlf4WuWeavmU4qweGea99aCVpmuBxy+pSFiXbOxl1na pxiYFibcNJqoz0yNXerHt43voY+IUcnA5KVKQEzAsJBAg2j1II/lWz+1Xt8tOIDYcS rrqUo6g0Cm1AXxrGMwSZk88LGjgEssULQCcBxfvHIKdWRVBsTy8jcTm/Yjkz5aW3b+ yg0ZTfNYRNctND6D2ofc+GtqqOjtiQYA8sdw6okGEnnBDPpVXrytcLEvGh0SISrhYv iJIQXWPbMf1zw== Message-ID: <6b8007c0-758a-c2f3-66df-7daf40cea724@beccati.com> Date: Mon, 12 Apr 2021 14:13:42 +0200 MIME-Version: 1.0 Content-Language: en-GB To: Nikita Popov , PHP internals References: In-Reply-To: Content-Type: text/plain; charset=UTF-8; format=flowed Content-Transfer-Encoding: 7bit Subject: Re: [PHP-DEV] Allow commit() without transaction? From: php@beccati.com (Matteo Beccati) Hi Nikita, On 12/04/2021 14:07, Nikita Popov wrote: > $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? I agree. As a user I'd prefer to be alerted that the transaction was not actually active rather than relying on seemingly working code that doesn't do what's on the tin. In fact I probably never knew about this particular MySQL quirk and most likely I had been fooled many times into thinking that the code above was a single transaction. Cheers -- Matteo Beccati Development & Consulting - http://www.beccati.com/