3v4l.org

run code in 300+ PHP versions simultaneously
<?php // 実行 $testNestedTransactions = new TestNestedTransactions(); $testNestedTransactions->createTables(); // CREATE TABLE $result = $testNestedTransactions->insert(); // INSERT echo "<p>{$result}</p>"; // 結果 // データベース接続 final class Database { private static array $instances = []; // データベース接続 final public static function getInstance(string $name): \PDO { if (!isset(self::$instances[$name])) { // データベース接続情報 $config = [ 'db1' => [ 'dsn' => 'mysql:host=localhost;dbname=mydb1', 'username' => 'myuser1', 'password' => 'mypassword1' ] ]; if (!isset($config[$name])) { throw new \DomainException(json_encode_noesc_slashes([ 'message' => 'Invalid database name: ' . $name ])); } $dbConfig = $config[$name]; $dsn = $dbConfig['dsn']; $username = $dbConfig['username']; $password = $dbConfig['password']; self::$instances[$name] = new \PDO($dsn, $username, $password); } return self::$instances[$name]; } } // 入れ子のトランザクション final class TestNestedTransactions { private \PDO $pdo; public function __construct() { $this->pdo = Database::getInstance('db1'); } // テーブル作成 final public function createTables(): void { try { $this->pdo->query(" CREATE TABLE IF NOT EXISTS test_table1 ( id INT AUTO_INCREMENT PRIMARY KEY, column1 VARCHAR(255) NOT NULL ) "); $this->pdo->query(" CREATE TABLE IF NOT EXISTS test_table2 ( id INT AUTO_INCREMENT PRIMARY KEY, column2 VARCHAR(255) NOT NULL ) "); } catch (\PDOException $e) { echo $e->getMessage(); } } // 入れ子のトランザクションで INSERT を実行 final public function insert(): string { try { // 外側のトランザクション開始 $this->pdo->beginTransaction(); // test_table1 の INSERT を実行 $stmt1 = $this->pdo->prepare("INSERT INTO test_table1 (column1) VALUES (:value1)"); $value1 = 'some_value_1'; $stmt1->bindParam(':value1', $value1); $stmt1->execute(); try { // 入れ子のトランザクション開始 $this->pdo->beginTransaction(); // test_table2 の INSERT を実行 $stmt2 = $this->pdo->prepare("INSERT INTO test_table2 (column2) VALUES (:value2)"); $value2 = 'some_value_2'; $stmt2->bindParam(':value2', $value2); $stmt2->execute(); // 入れ子のトランザクションのコミット $this->pdo->commit(); } catch (\Exception $e) { // 入れ子のトランザクションのロールバック $this->pdo->rollBack(); throw $e; } // 外側のトランザクションのコミット $this->pdo->commit(); return "成功"; } catch (\Exception $e) { // 外側のトランザクションのロールバック $this->pdo->rollBack(); // この行でエラーが発生 return "エラー: " . $e->getMessage(); } } }

Here you find the average performance (time & memory) of each version. A grayed out version indicates it didn't complete successfully (based on exit-code).

VersionSystem time (s)User time (s)Memory (MiB)
8.5.00.0160.00819.96
8.4.150.0010.00114.05
8.4.140.0110.00917.72
8.4.130.0040.00517.76
8.4.120.0140.00620.30
8.4.110.0120.00922.49
8.4.100.0130.00817.95
8.4.90.0050.00518.83
8.4.80.0130.00617.78
8.4.70.0050.00518.16
8.4.60.0050.00418.11
8.4.50.0050.00517.80
8.4.40.0130.00717.82
8.4.30.0160.00318.96
8.4.20.0150.00018.95
8.4.10.0030.01619.68
8.3.280.0140.01018.37
8.3.270.0090.01016.54
8.3.260.0090.01216.66
8.3.250.0090.01019.22
8.3.240.0130.00716.40
8.3.230.0110.00916.67
8.3.220.0060.01117.05
8.3.210.0110.00716.72
8.3.200.0040.00416.65
8.3.190.0030.00516.70
8.3.180.0120.00718.23
8.3.170.0160.00318.73
8.3.160.0100.00720.68
8.3.150.0140.00418.63
8.3.140.0040.01416.65
8.3.130.0130.00718.21
8.3.120.0060.00319.15
8.3.110.0000.00920.94
8.3.100.0040.01118.24
8.3.90.0170.00026.77
8.3.80.0060.00317.97
8.3.70.0140.00716.75
8.3.60.0110.01118.44
8.3.50.0120.00318.66
8.3.40.0030.01020.13
8.3.30.0060.00920.17
8.3.20.0000.00824.18
8.3.10.0050.00224.66
8.3.00.0130.00728.09
8.2.290.0080.01022.23
8.2.280.0050.00318.70
8.2.270.0110.00418.73
8.2.260.0000.00918.34
8.2.250.0110.00718.68
8.2.240.0070.00318.76
8.2.230.0070.00322.58
8.2.220.0080.00024.06
8.2.210.0080.00026.77
8.2.200.0000.01016.75
8.2.190.0120.00616.88
8.2.180.0070.01418.55
8.2.170.0140.00719.02
8.2.160.0100.00322.96
8.2.150.0040.00425.66
8.2.140.0080.00024.66
8.2.130.0150.00328.09
8.2.120.0070.01128.09
8.2.110.0120.00628.09
8.2.100.0100.01028.09
8.2.90.0100.01028.09
8.2.80.0030.01728.09
8.2.70.0120.00828.09
8.2.60.0070.01428.09
8.2.50.0110.00828.09
8.2.40.0190.00328.09
8.2.30.0170.00028.09
8.2.20.0130.00728.09
8.2.10.0040.01228.09
8.2.00.0040.01228.09
8.1.330.0120.00722.00
8.1.320.0120.00816.53
8.1.310.0090.00918.43
8.1.300.0130.00617.03
8.1.290.0110.00030.84
8.1.280.0120.00625.92
8.1.270.0090.00620.76
8.1.260.0170.00328.09
8.1.250.0170.00328.09
8.1.240.0060.01228.09
8.1.230.0100.01328.09
8.1.220.0070.00228.09
8.1.210.0090.00428.09
8.1.200.0060.00328.09
8.1.190.0130.00628.09
8.1.180.0130.00628.09
8.1.170.0100.01028.09
8.1.160.0090.00628.09
8.1.150.0030.00628.09
8.1.140.0090.00028.09
8.1.130.0090.00628.09
8.1.120.0030.00628.09
8.1.110.0060.00628.09
8.1.100.0110.00028.09
8.1.90.0060.00328.09
8.1.80.0040.00428.09
8.1.70.0080.00828.09
8.1.60.0170.00328.09
8.1.50.0030.00628.09
8.1.40.0060.00328.09
8.1.30.0110.00728.09
8.1.20.0030.00628.09
8.1.10.0040.00428.09
8.1.00.0070.01028.09

preferences:
66.14 ms | 403 KiB | 5 Q