From 052a26d7eb20ee5235b285ee689fa81d9ed1af2d Mon Sep 17 00:00:00 2001 From: Markus Staab Date: Thu, 7 Nov 2024 14:27:24 +0100 Subject: [PATCH] .env: Support ssl-certificates via DBA_SSL --- .gitignore | 1 + tests/ReflectorFactory.php | 9 +++++++-- 2 files changed, 8 insertions(+), 2 deletions(-) diff --git a/.gitignore b/.gitignore index 9078c1d54..cf6fd38b1 100644 --- a/.gitignore +++ b/.gitignore @@ -12,3 +12,4 @@ pdo.php .idea/ /test.php +/mysql80ab-cert.pem diff --git a/tests/ReflectorFactory.php b/tests/ReflectorFactory.php index d3e5937f7..758b78101 100644 --- a/tests/ReflectorFactory.php +++ b/tests/ReflectorFactory.php @@ -39,7 +39,7 @@ public static function create(string $cacheDir): QueryReflector $user = getenv('DBA_USER') ?: $_ENV['DBA_USER']; $password = getenv('DBA_PASSWORD') ?: $_ENV['DBA_PASSWORD']; $dbname = getenv('DBA_DATABASE') ?: $_ENV['DBA_DATABASE']; - $ssl = (bool) (getenv('DBA_SSL') ?: $_ENV['DBA_SSL'] ?? false); + $ssl = (string) (getenv('DBA_SSL') ?: $_ENV['DBA_SSL'] ?? ''); $mode = getenv('DBA_MODE') ?: $_ENV['DBA_MODE']; $reflector = getenv('DBA_REFLECTOR') ?: $_ENV['DBA_REFLECTOR']; } @@ -80,7 +80,12 @@ public static function create(string $cacheDir): QueryReflector $reflector = new MysqliQueryReflector($mysqli); $schemaHasher = new SchemaHasherMysql($mysqli); } elseif ('pdo-mysql' === $reflector) { - $pdo = new PDO(sprintf('mysql:dbname=%s;host=%s', $dbname, $host), $user, $password); + $options = []; + if ($ssl !== '') { + $options[PDO::MYSQL_ATTR_SSL_CA] = $ssl; + $options[PDO::MYSQL_ATTR_SSL_VERIFY_SERVER_CERT] = false; + } + $pdo = new PDO(sprintf('mysql:dbname=%s;host=%s', $dbname, $host), $user, $password, $options); $reflector = new PdoMysqlQueryReflector($pdo); $schemaHasher = new SchemaHasherMysql($pdo); } elseif ('pdo-pgsql' === $reflector) {