diff --git a/.github/workflows/ci.yml b/.github/workflows/ci.yml index 006b11612..418de9ac3 100644 --- a/.github/workflows/ci.yml +++ b/.github/workflows/ci.yml @@ -14,7 +14,7 @@ jobs: strategy: fail-fast: false matrix: - php-version: ['8.1', '8.4'] + php-version: ['8.1', '8.5'] db-type: [sqlite, mysql, pgsql] prefer-lowest: [''] include: @@ -27,7 +27,7 @@ jobs: steps: - name: Setup MySQL latest - if: matrix.db-type == 'mysql' && matrix.php-version == '8.4' + if: matrix.db-type == 'mysql' && matrix.php-version == '8.5' run: docker run --rm --name=mysqld -e MYSQL_ROOT_PASSWORD=root -e MYSQL_DATABASE=cakephp -p 3306:3306 -d mysql:8.4 - name: Setup MySQL 8.0 diff --git a/src/Phinx/Db/Adapter/MysqlAdapter.php b/src/Phinx/Db/Adapter/MysqlAdapter.php index 8a767a74b..332d10780 100644 --- a/src/Phinx/Db/Adapter/MysqlAdapter.php +++ b/src/Phinx/Db/Adapter/MysqlAdapter.php @@ -147,7 +147,11 @@ public function connect(): void // https://php.net/manual/en/ref.pdo-mysql.php#pdo-mysql.constants foreach ($options as $key => $option) { if (strpos($key, 'mysql_attr_') === 0) { - $pdoConstant = '\PDO::' . strtoupper($key); + if (PHP_VERSION_ID < 80400) { + $pdoConstant = '\PDO::' . strtoupper($key); + } else { + $pdoConstant = '\PDO\Mysql::' . strtoupper(substr($key, 6)); + } if (!defined($pdoConstant)) { throw new UnexpectedValueException('Invalid PDO attribute: ' . $key . ' (' . $pdoConstant . ')'); } diff --git a/tests/Phinx/Db/Adapter/MysqlAdapterTest.php b/tests/Phinx/Db/Adapter/MysqlAdapterTest.php index 1b6ec3d47..a2840e0b5 100644 --- a/tests/Phinx/Db/Adapter/MysqlAdapterTest.php +++ b/tests/Phinx/Db/Adapter/MysqlAdapterTest.php @@ -2731,19 +2731,19 @@ public function testCreateTableWithPrecisionCurrentTimestamp() public function pdoAttributeProvider() { return [ - ['mysql_attr_invalid'], - ['attr_invalid'], + ['mysql_attr_invalid', PHP_VERSION_ID < 80400 ? '\PDO::MYSQL_ATTR_INVALID' : '\PDO\Mysql::ATTR_INVALID'], + ['attr_invalid', '\PDO::ATTR_INVALID'], ]; } /** * @dataProvider pdoAttributeProvider */ - public function testInvalidPdoAttribute($attribute) + public function testInvalidPdoAttribute($attribute, $constant) { $adapter = new MysqlAdapter(MYSQL_DB_CONFIG + [$attribute => true]); $this->expectException(UnexpectedValueException::class); - $this->expectExceptionMessage('Invalid PDO attribute: ' . $attribute . ' (\PDO::' . strtoupper($attribute) . ')'); + $this->expectExceptionMessage('Invalid PDO attribute: ' . $attribute . ' (' . $constant . ')'); $adapter->connect(); } @@ -2797,4 +2797,18 @@ public function testPdoNotPersistentConnection() $adapter = new MysqlAdapter(MYSQL_DB_CONFIG); $this->assertFalse($adapter->getConnection()->getAttribute(PDO::ATTR_PERSISTENT)); } + + public function testMysqlPdoMultiStatementsEnabled() + { + $adapter = new MysqlAdapter(MYSQL_DB_CONFIG + ['mysql_attr_multi_statements' => true]); + $result = $adapter->fetchAll('SELECT 1 a; SELECT 2 b;'); + $this->assertSame([['a' => 1, 0 => 1]], $result); + } + + public function testMysqlPdoMultiStatementsDisabled() + { + $adapter = new MysqlAdapter(MYSQL_DB_CONFIG + ['mysql_attr_multi_statements' => false]); + $this->expectException(PDOException::class); + $adapter->fetchAll('SELECT 1 a; SELECT 2 b;'); + } }