LoginSignup
0
1

More than 1 year has passed since last update.

PHP8でPDO::inTransactionの挙動が変わった

Posted at

PHP8では、PDO::inTransactionでDBサーバの状態も見るようになった

PHP8で、PDO::inTransactionの挙動が変わりました。
PHP: 下位互換性のない変更点 - Manual

PDO::inTransaction() は、 PDO が管理しているおおよその情報ではなく、 実際のトランザクションの状態を報告するようになりました。

だいぶざっくりした書き方だな・・・と思ったのでいろいろ調べてみると、下記でinTransactionの判定にMySQLサーバの状態を確認するコードが入ったようです。
(php-8.0.0RC2から適用。php7.4.27までのコードには入っていない。)
https://github.com/php/php-src/pull/4996

今まではbeginTransaction()を使ってトランザクションが開始されたかどうかのみを判定しており、それ以外の方法で開始されたトランザクションは検出できなかったとのこと。
PHP: PDO::inTransaction - Manual

This will only detect whether a transaction has been started using beginTransaction(). It will not be able to detect transactions started by any other means, for example by executing "START TRANSACTION".

が、PHP8からは、DBサーバの状態も確認した結果を返却するようになリました。

inTransactionを使って色々してる部分はPHP8にバージョンアップする際に確認が必要そうですね。

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1