-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathConfigExternal.php
More file actions
38 lines (31 loc) · 1.16 KB
/
ConfigExternal.php
File metadata and controls
38 lines (31 loc) · 1.16 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
<?php
// Load database configuration from session
$mysqlDbServer = $_SESSION['DbHost'] ?? '';
$mysqlDbPort = $_SESSION['DbPort'] ?? ''; // Optional
$mysqlDbName = $_SESSION['DbName'] ?? '';
$mysqlDbUser = $_SESSION['DbUser'] ?? '';
$mysqlDbPassword = $_SESSION['DbPassword'] ?? '';
$mysqlDbDriver = $_SESSION['DbDriver'] ?? 'mysql';
// Construct DSN
$dsn = "$mysqlDbDriver:host=$mysqlDbServer";
if (!empty($mysqlDbPort)) {
$dsn .= ";port=$mysqlDbPort";
}
$dsn .= ";dbname=$mysqlDbName;charset=utf8mb4";
// Show all errors
ini_set("error_reporting", E_ALL);
ini_set("display_errors", 1);
try {
// Create a new PDO instance
$conn = new PDO($dsn, $mysqlDbUser, $mysqlDbPassword);
// Set the PDO error mode to exception
$conn->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$configLoaded = true; // Configuration loaded successfully
} catch (PDOException $e) {
// Handle connection error
printf("Connection to database couldn't be made: %s\n", $e->getMessage());
echo "<meta http-equiv=refresh content=3>";
echo "<br><br>Please send this error reporting to an administrator so we can fix the problem.";
exit();
}
?>