Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

.env: Support ssl-certificates via DBA_SSL #702

Merged
merged 1 commit into from
Nov 7, 2024
Merged
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
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