Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions .github/workflows/ci.yml
Original file line number Diff line number Diff line change
Expand Up @@ -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:
Expand All @@ -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
Expand Down
6 changes: 5 additions & 1 deletion src/Phinx/Db/Adapter/MysqlAdapter.php
Original file line number Diff line number Diff line change
Expand Up @@ -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 . ')');
}
Expand Down
22 changes: 18 additions & 4 deletions tests/Phinx/Db/Adapter/MysqlAdapterTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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();
}

Expand Down Expand Up @@ -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;');
}
}