@@ -1750,14 +1750,7 @@ func statusLevelForKey(status domain.SystemStatus, key string) (domain.StatusLev
17501750 return domain .StatusError , false
17511751}
17521752
1753- func testDatabaseConnection (ctx context.Context , workDir string , cfg dbConfig ) (bool , string , error ) {
1754- raw , err := json .Marshal (cfg )
1755- if err != nil {
1756- return false , "" , err
1757- }
1758- encoded := base64 .StdEncoding .EncodeToString (raw )
1759-
1760- script := `
1753+ const dbConnectionTestScript = `
17611754$cfg = json_decode(base64_decode($argv[1] ?? ''), true);
17621755if (!is_array($cfg)) { echo json_encode(["ok"=>false,"error"=>"Invalid config"]); exit(0); }
17631756$type = $cfg["type"] ?? "mysql";
@@ -1782,7 +1775,7 @@ try {
17821775 echo json_encode(["ok"=>true]); exit(0);
17831776 }
17841777 $dsnNoDb = match($type) {
1785- "pgsql" => "pgsql:host={$host};port={$port}",
1778+ "pgsql" => $port > 0 ? "pgsql:host={$host};port={$port};dbname=postgres" : "pgsql:host={$host};dbname=postgres ",
17861779 "sqlsrv" => $port > 0 ? "sqlsrv:Server={$host},{$port}" : "sqlsrv:Server={$host}",
17871780 default => "mysql:host={$host};port={$port};charset=utf8mb4",
17881781 };
@@ -1807,6 +1800,15 @@ try {
18071800}
18081801`
18091802
1803+ func testDatabaseConnection (ctx context.Context , workDir string , cfg dbConfig ) (bool , string , error ) {
1804+ raw , err := json .Marshal (cfg )
1805+ if err != nil {
1806+ return false , "" , err
1807+ }
1808+ encoded := base64 .StdEncoding .EncodeToString (raw )
1809+
1810+ script := dbConnectionTestScript
1811+
18101812 cmd := exec .CommandContext (ctx , "php" , "-r" , script , encoded )
18111813 if strings .TrimSpace (workDir ) != "" {
18121814 cmd .Dir = workDir
0 commit comments