Skip to content

Commit e746c08

Browse files
Allowed an issues with connecting to the database to correctly print out an error. This wasn't being caught before.
1 parent 1b72314 commit e746c08

File tree

1 file changed

+7
-7
lines changed

1 file changed

+7
-7
lines changed

database_connection.php

Lines changed: 7 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -11,10 +11,10 @@
1111
mysqli_report(MYSQLI_REPORT_ERROR | MYSQLI_REPORT_STRICT);
1212

1313
// Connect to the database.
14-
$mysqli = new mysqli($databaseHost, $databaseUsername, $databasePassword, $databaseName);
15-
16-
if (!$mysqli) {
17-
// If
18-
echo "Database connection failed.";
19-
die();
20-
}
14+
try {
15+
$mysqli = new mysqli($databaseHost, $databaseUsername, $databasePassword, $databaseName);
16+
} catch (mysqli_sql_exception $e) {
17+
// An error occurred when attempting to connect to the database.
18+
print('MySQLi connection error: ' . $e->getMessage() . ' in ' . $e->getFile() . ' on line ' . $e->getLine());
19+
exit();
20+
}

0 commit comments

Comments
 (0)