From 6c41d90b548e196bc3add482867131b99b1900a1 Mon Sep 17 00:00:00 2001 From: Jamie Date: Fri, 16 May 2025 16:53:11 +0100 Subject: [PATCH 1/6] use ssl-mode=disabled for newer mysql --- src/Illuminate/Database/Schema/MySqlSchemaState.php | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Schema/MySqlSchemaState.php b/src/Illuminate/Database/Schema/MySqlSchemaState.php index 1635de7742e5..31c61932a994 100644 --- a/src/Illuminate/Database/Schema/MySqlSchemaState.php +++ b/src/Illuminate/Database/Schema/MySqlSchemaState.php @@ -5,6 +5,7 @@ use Exception; use Illuminate\Database\Connection; use Illuminate\Support\Str; +use PDO; use Symfony\Component\Process\Process; class MySqlSchemaState extends SchemaState @@ -117,7 +118,12 @@ protected function connectionString() if (isset($config['options'][\PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT]) && $config['options'][\PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] === false) { - $value .= ' --ssl=off'; + + $version = $this->connection->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION); + + $value .= version_compare($version, '8.0.40', '<') + ? ' --ssl=off' + : ' --ssl-mode=DISABLED'; } return $value; From 38e2747a618ff63c95bd29172269e577244168d2 Mon Sep 17 00:00:00 2001 From: Jamie Date: Fri, 16 May 2025 17:19:55 +0100 Subject: [PATCH 2/6] use client version --- src/Illuminate/Database/Schema/MySqlSchemaState.php | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/Illuminate/Database/Schema/MySqlSchemaState.php b/src/Illuminate/Database/Schema/MySqlSchemaState.php index 31c61932a994..4e5580560be0 100644 --- a/src/Illuminate/Database/Schema/MySqlSchemaState.php +++ b/src/Illuminate/Database/Schema/MySqlSchemaState.php @@ -119,7 +119,7 @@ protected function connectionString() if (isset($config['options'][\PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT]) && $config['options'][\PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] === false) { - $version = $this->connection->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION); + $version = $this->connection->getPdo()->getAttribute(PDO::ATTR_CLIENT_VERSION); $value .= version_compare($version, '8.0.40', '<') ? ' --ssl=off' From 1c949188707cefe609038992806ef44dd0ef135f Mon Sep 17 00:00:00 2001 From: Jamie Date: Fri, 16 May 2025 17:20:04 +0100 Subject: [PATCH 3/6] test pdo bits --- tests/Database/DatabaseMySqlSchemaStateTest.php | 11 ++++++++--- 1 file changed, 8 insertions(+), 3 deletions(-) diff --git a/tests/Database/DatabaseMySqlSchemaStateTest.php b/tests/Database/DatabaseMySqlSchemaStateTest.php index 18985114e509..da928a79a8fd 100644 --- a/tests/Database/DatabaseMySqlSchemaStateTest.php +++ b/tests/Database/DatabaseMySqlSchemaStateTest.php @@ -6,6 +6,7 @@ use Generator; use Illuminate\Database\MySqlConnection; use Illuminate\Database\Schema\MySqlSchemaState; +use PDO; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use ReflectionMethod; @@ -16,8 +17,12 @@ class DatabaseMySqlSchemaStateTest extends TestCase #[DataProvider('provider')] public function testConnectionString(string $expectedConnectionString, array $expectedVariables, array $dbConfig): void { + $pdo = $this->createMock(PDO::class); + $pdo->method('getAttribute')->with(PDO::ATTR_CLIENT_VERSION)->willReturn('8.0.40'); + $connection = $this->createMock(MySqlConnection::class); $connection->method('getConfig')->willReturn($dbConfig); + $connection->method('getPdo')->willReturn($pdo); $schemaState = new MySqlSchemaState($connection); @@ -65,13 +70,13 @@ public static function provider(): Generator 'username' => 'root', 'database' => 'forge', 'options' => [ - \PDO::MYSQL_ATTR_SSL_CA => 'ssl.ca', + PDO::MYSQL_ATTR_SSL_CA => 'ssl.ca', ], ], ]; yield 'no_ssl' => [ - ' --user="${:LARAVEL_LOAD_USER}" --password="${:LARAVEL_LOAD_PASSWORD}" --host="${:LARAVEL_LOAD_HOST}" --port="${:LARAVEL_LOAD_PORT}" --ssl=off', [ + ' --user="${:LARAVEL_LOAD_USER}" --password="${:LARAVEL_LOAD_PASSWORD}" --host="${:LARAVEL_LOAD_HOST}" --port="${:LARAVEL_LOAD_PORT}" --ssl-mode=DISABLED', [ 'LARAVEL_LOAD_SOCKET' => '', 'LARAVEL_LOAD_HOST' => '', 'LARAVEL_LOAD_PORT' => '', @@ -83,7 +88,7 @@ public static function provider(): Generator 'username' => 'root', 'database' => 'forge', 'options' => [ - \PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false, + PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false, ], ], ]; From ef8a46ee1a4b4d4ea6e0a4d49e27aa98721381ed Mon Sep 17 00:00:00 2001 From: Jamie Date: Fri, 16 May 2025 17:26:37 +0100 Subject: [PATCH 4/6] server version --- src/Illuminate/Database/Schema/MySqlSchemaState.php | 2 +- tests/Database/DatabaseMySqlSchemaStateTest.php | 2 +- 2 files changed, 2 insertions(+), 2 deletions(-) diff --git a/src/Illuminate/Database/Schema/MySqlSchemaState.php b/src/Illuminate/Database/Schema/MySqlSchemaState.php index 4e5580560be0..31c61932a994 100644 --- a/src/Illuminate/Database/Schema/MySqlSchemaState.php +++ b/src/Illuminate/Database/Schema/MySqlSchemaState.php @@ -119,7 +119,7 @@ protected function connectionString() if (isset($config['options'][\PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT]) && $config['options'][\PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] === false) { - $version = $this->connection->getPdo()->getAttribute(PDO::ATTR_CLIENT_VERSION); + $version = $this->connection->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION); $value .= version_compare($version, '8.0.40', '<') ? ' --ssl=off' diff --git a/tests/Database/DatabaseMySqlSchemaStateTest.php b/tests/Database/DatabaseMySqlSchemaStateTest.php index da928a79a8fd..d82d524cfc11 100644 --- a/tests/Database/DatabaseMySqlSchemaStateTest.php +++ b/tests/Database/DatabaseMySqlSchemaStateTest.php @@ -18,7 +18,7 @@ class DatabaseMySqlSchemaStateTest extends TestCase public function testConnectionString(string $expectedConnectionString, array $expectedVariables, array $dbConfig): void { $pdo = $this->createMock(PDO::class); - $pdo->method('getAttribute')->with(PDO::ATTR_CLIENT_VERSION)->willReturn('8.0.40'); + $pdo->method('getAttribute')->with(PDO::ATTR_SERVER_VERSION)->willReturn('8.0.40'); $connection = $this->createMock(MySqlConnection::class); $connection->method('getConfig')->willReturn($dbConfig); From 973b28edc3f9fdce1e551955ba33a6dfc1064b6d Mon Sep 17 00:00:00 2001 From: Jamie Date: Fri, 16 May 2025 17:27:44 +0100 Subject: [PATCH 5/6] fix cs --- src/Illuminate/Database/Schema/MySqlSchemaState.php | 1 - 1 file changed, 1 deletion(-) diff --git a/src/Illuminate/Database/Schema/MySqlSchemaState.php b/src/Illuminate/Database/Schema/MySqlSchemaState.php index 31c61932a994..671377c4efd7 100644 --- a/src/Illuminate/Database/Schema/MySqlSchemaState.php +++ b/src/Illuminate/Database/Schema/MySqlSchemaState.php @@ -118,7 +118,6 @@ protected function connectionString() if (isset($config['options'][\PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT]) && $config['options'][\PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] === false) { - $version = $this->connection->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION); $value .= version_compare($version, '8.0.40', '<') From e91c4b3b6e3d102cd43a8108025e68ed71444693 Mon Sep 17 00:00:00 2001 From: Jamie Date: Fri, 16 May 2025 17:31:39 +0100 Subject: [PATCH 6/6] no pdo use --- src/Illuminate/Database/Schema/MySqlSchemaState.php | 3 +-- tests/Database/DatabaseMySqlSchemaStateTest.php | 9 ++++----- 2 files changed, 5 insertions(+), 7 deletions(-) diff --git a/src/Illuminate/Database/Schema/MySqlSchemaState.php b/src/Illuminate/Database/Schema/MySqlSchemaState.php index 671377c4efd7..0fe0bf2d4eb0 100644 --- a/src/Illuminate/Database/Schema/MySqlSchemaState.php +++ b/src/Illuminate/Database/Schema/MySqlSchemaState.php @@ -5,7 +5,6 @@ use Exception; use Illuminate\Database\Connection; use Illuminate\Support\Str; -use PDO; use Symfony\Component\Process\Process; class MySqlSchemaState extends SchemaState @@ -118,7 +117,7 @@ protected function connectionString() if (isset($config['options'][\PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT]) && $config['options'][\PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] === false) { - $version = $this->connection->getPdo()->getAttribute(PDO::ATTR_SERVER_VERSION); + $version = $this->connection->getPdo()->getAttribute(\PDO::ATTR_SERVER_VERSION); $value .= version_compare($version, '8.0.40', '<') ? ' --ssl=off' diff --git a/tests/Database/DatabaseMySqlSchemaStateTest.php b/tests/Database/DatabaseMySqlSchemaStateTest.php index d82d524cfc11..783a1ee112e9 100644 --- a/tests/Database/DatabaseMySqlSchemaStateTest.php +++ b/tests/Database/DatabaseMySqlSchemaStateTest.php @@ -6,7 +6,6 @@ use Generator; use Illuminate\Database\MySqlConnection; use Illuminate\Database\Schema\MySqlSchemaState; -use PDO; use PHPUnit\Framework\Attributes\DataProvider; use PHPUnit\Framework\TestCase; use ReflectionMethod; @@ -17,8 +16,8 @@ class DatabaseMySqlSchemaStateTest extends TestCase #[DataProvider('provider')] public function testConnectionString(string $expectedConnectionString, array $expectedVariables, array $dbConfig): void { - $pdo = $this->createMock(PDO::class); - $pdo->method('getAttribute')->with(PDO::ATTR_SERVER_VERSION)->willReturn('8.0.40'); + $pdo = $this->createMock(\PDO::class); + $pdo->method('getAttribute')->with(\PDO::ATTR_SERVER_VERSION)->willReturn('8.0.40'); $connection = $this->createMock(MySqlConnection::class); $connection->method('getConfig')->willReturn($dbConfig); @@ -70,7 +69,7 @@ public static function provider(): Generator 'username' => 'root', 'database' => 'forge', 'options' => [ - PDO::MYSQL_ATTR_SSL_CA => 'ssl.ca', + \PDO::MYSQL_ATTR_SSL_CA => 'ssl.ca', ], ], ]; @@ -88,7 +87,7 @@ public static function provider(): Generator 'username' => 'root', 'database' => 'forge', 'options' => [ - PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false, + \PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT => false, ], ], ];