forked from FWS/FWS-TEMPLATE-Website-OnePage
fix(api): report a missing PDO SQLite driver with a clear message
On bare Windows PHP installs the pdo_sqlite extension is often disabled; wrap the PDO connection so the failure surfaces as an actionable error instead of a bare driver exception.
This commit is contained in:
1 file changed
+12
-1
+12
-1
@@ -52,7 +52,18 @@ function fws_bugs_db(): PDO
|
||||
mkdir($dir, 0775, true);
|
||||
}
|
||||
|
||||
$pdo = new PDO('sqlite:' . $dir . '/fws_bugs.sqlite');
|
||||
try {
|
||||
$pdo = new PDO('sqlite:' . $dir . '/fws_bugs.sqlite');
|
||||
} catch (Throwable $e) {
|
||||
/* Driver PDO SQLite absent (cas fréquent : WAMP/XAMPP où pdo_sqlite
|
||||
et sqlite3 sont à activer dans php.ini). Message clair au lieu d'un
|
||||
crash avec stack trace. */
|
||||
throw new RuntimeException(
|
||||
'Extension PDO SQLite indisponible : activez "extension=pdo_sqlite" et "extension=sqlite3" dans php.ini.',
|
||||
0,
|
||||
$e
|
||||
);
|
||||
}
|
||||
$pdo->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
|
||||
$pdo->setAttribute(PDO::ATTR_DEFAULT_FETCH_MODE, PDO::FETCH_ASSOC);
|
||||
|
||||
|
||||
Reference in new issue
Block a user