Skip to content

Commit

Permalink
.env: Support ssl-certificates via DBA_SSL
Browse files Browse the repository at this point in the history
  • Loading branch information
staabm committed Nov 7, 2024
1 parent 08a068d commit 052a26d
Show file tree
Hide file tree
Showing 2 changed files with 8 additions and 2 deletions.
1 change: 1 addition & 0 deletions .gitignore
Original file line number Diff line number Diff line change
Expand Up @@ -12,3 +12,4 @@ pdo.php
.idea/

/test.php
/mysql80ab-cert.pem
9 changes: 7 additions & 2 deletions tests/ReflectorFactory.php
Original file line number Diff line number Diff line change
Expand Up @@ -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'];
}
Expand Down Expand Up @@ -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) {
Expand Down

0 comments on commit 052a26d

Please sign in to comment.