feat: enhance database connection error handling and add MySQL driver check
This commit is contained in:
@@ -13,3 +13,4 @@ APP_URL="https://uw-domein.nl"
|
|||||||
|
|
||||||
# Applicatie Geheime Sleutel (willekeurige tekenreeks)
|
# Applicatie Geheime Sleutel (willekeurige tekenreeks)
|
||||||
APP_SECRET="fociz-maria-db-super-secret-key-998877"
|
APP_SECRET="fociz-maria-db-super-secret-key-998877"
|
||||||
|
|
||||||
|
|||||||
+45
-4
@@ -9,6 +9,36 @@ function get_db_connection(): PDO {
|
|||||||
static $pdo = null;
|
static $pdo = null;
|
||||||
|
|
||||||
if ($pdo === null) {
|
if ($pdo === null) {
|
||||||
|
// Controleer of de PDO MySQL/MariaDB driver überhaupt aanwezig is in deze PHP installatie
|
||||||
|
$availableDrivers = PDO::getAvailableDrivers();
|
||||||
|
if (!in_array('mysql', $availableDrivers)) {
|
||||||
|
$driversList = !empty($availableDrivers) ? implode(', ', $availableDrivers) : 'geen';
|
||||||
|
die("
|
||||||
|
<div style='font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto, sans-serif; background: #090d16; color: #f1f5f9; min-height: 100vh; display: flex; align-items: center; justify-content: center; padding: 20px;'>
|
||||||
|
<div style='max-width: 580px; background: #111827; border: 1px solid #ef4444; border-radius: 16px; padding: 30px; box-shadow: 0 20px 25px -5px rgba(0,0,0,0.5);'>
|
||||||
|
<h2 style='color: #ef4444; margin-top: 0; display: flex; align-items: center; gap: 8px;'>
|
||||||
|
⚠️ PHP MySQL Driver Ontbreekt (pdo_mysql)
|
||||||
|
</h2>
|
||||||
|
<p style='color: #94a3b8; font-size: 14px; line-height: 1.6;'>
|
||||||
|
De PHP-installatie op uw server heeft momenteel de <strong>pdo_mysql</strong> extensie niet ingeschakeld. Zonder deze driver kan PHP geen verbinding maken met MariaDB.
|
||||||
|
</p>
|
||||||
|
<div style='background: #0b0f17; border: 1px solid #1f2937; border-radius: 10px; padding: 15px; margin: 20px 0;'>
|
||||||
|
<strong style='color: #38bdf8; font-size: 13px; display: block; margin-bottom: 8px;'>Oplossing per servertype:</strong>
|
||||||
|
<ul style='color: #e2e8f0; font-size: 13px; margin: 0; padding-left: 20px; line-height: 1.8;'>
|
||||||
|
<li><strong>Ubuntu / Debian:</strong><br><code style='color: #4ade80; background: #000; padding: 2px 6px; border-radius: 4px;'>sudo apt install php-mysql && sudo systemctl restart apache2</code> (of php-fpm)</li>
|
||||||
|
<li><strong>CentOS / RHEL / AlmaLinux:</strong><br><code style='color: #4ade80; background: #000; padding: 2px 6px; border-radius: 4px;'>sudo dnf install php-mysqlnd && sudo systemctl restart httpd</code></li>
|
||||||
|
<li><strong>cPanel / DirectAdmin / Plesk:</strong><br>Ga naar <em>Select PHP Version → Extensions</em> en vink <strong>pdo_mysql</strong> (en <strong>nd_pdo_mysql</strong> of <strong>mysqlnd</strong>) aan.</li>
|
||||||
|
<li><strong>Windows / XAMPP:</strong><br>Verwijder de puntkomma <code>;</code> voor <code>extension=pdo_mysql</code> in uw <code>php.ini</code> en herstart Apache.</li>
|
||||||
|
</ul>
|
||||||
|
</div>
|
||||||
|
<div style='font-size: 11px; color: #64748b;'>
|
||||||
|
PHP Versie: " . PHP_VERSION . " • Momenteel actieve drivers: " . htmlspecialchars($driversList) . "
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
");
|
||||||
|
}
|
||||||
|
|
||||||
$dsn = sprintf(
|
$dsn = sprintf(
|
||||||
'mysql:host=%s;port=%s;dbname=%s;charset=%s',
|
'mysql:host=%s;port=%s;dbname=%s;charset=%s',
|
||||||
DB_HOST,
|
DB_HOST,
|
||||||
@@ -21,6 +51,7 @@ function get_db_connection(): PDO {
|
|||||||
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
||||||
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
||||||
PDO::ATTR_EMULATE_PREPARES => false,
|
PDO::ATTR_EMULATE_PREPARES => false,
|
||||||
|
PDO::ATTR_TIMEOUT => 5,
|
||||||
];
|
];
|
||||||
|
|
||||||
try {
|
try {
|
||||||
@@ -38,10 +69,21 @@ function get_db_connection(): PDO {
|
|||||||
ensure_tables_exist($pdo);
|
ensure_tables_exist($pdo);
|
||||||
return $pdo;
|
return $pdo;
|
||||||
} catch (PDOException $ex) {
|
} catch (PDOException $ex) {
|
||||||
die("Database verbindingsfout: Kan database '" . htmlspecialchars(DB_NAME) . "' niet aanmaken of vinden. Maak deze handmatig aan in MariaDB.");
|
die("Database verbindingsfout: Kan database '" . htmlspecialchars(DB_NAME) . "' niet aanmaken of vinden op " . htmlspecialchars(DB_HOST) . ". Maak deze handmatig aan in MariaDB.");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
die("MariaDB Verbindingsfout: " . htmlspecialchars($e->getMessage()) . "<br><small>Controleer uw instellingen in config/config.php of .env</small>");
|
die("
|
||||||
|
<div style='font-family: sans-serif; background: #090d16; color: #fff; padding: 40px; text-align: center;'>
|
||||||
|
<h2 style='color: #ef4444;'>MariaDB Verbindingsfout (" . htmlspecialchars((string)$e->getCode()) . ")</h2>
|
||||||
|
<p style='color: #cbd5e1;'>" . htmlspecialchars($e->getMessage()) . "</p>
|
||||||
|
<div style='background: #111827; display: inline-block; padding: 15px; border-radius: 8px; text-align: left; font-size: 13px; margin-top: 15px;'>
|
||||||
|
Host: <strong>" . htmlspecialchars(DB_HOST) . "</strong><br>
|
||||||
|
Poort: <strong>" . htmlspecialchars(DB_PORT) . "</strong><br>
|
||||||
|
Database: <strong>" . htmlspecialchars(DB_NAME) . "</strong><br>
|
||||||
|
Gebruiker: <strong>" . htmlspecialchars(DB_USER) . "</strong>
|
||||||
|
</div>
|
||||||
|
</div>
|
||||||
|
");
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
@@ -62,7 +104,6 @@ function ensure_tables_exist(PDO $pdo): void {
|
|||||||
}
|
}
|
||||||
}
|
}
|
||||||
} catch (PDOException $e) {
|
} catch (PDOException $e) {
|
||||||
// Tabellen bestaan waarschijnlijk al of er is een permissiebeperking
|
// Tabellen bestaan waarschijnlijk al
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|||||||
Reference in New Issue
Block a user