Skip to content

Commit 8c8e68f

Browse files
authored
Merge pull request #1691 from IrAlfred/improve-create-account-db-error-message
fix(other): add database connection checks and error handling
2 parents 9222f5d + cabc464 commit 8c8e68f

File tree

1 file changed

+15
-0
lines changed

1 file changed

+15
-0
lines changed

scripts/create_account.php

Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,21 @@
4343

4444
$auth = new Hm_Auth_DB($config);
4545

46+
$dbh = Hm_DB::connect($config);
47+
if ($dbh) {
48+
try {
49+
$result = $dbh->query("SELECT 1 FROM hm_user LIMIT 1");
50+
} catch (Exception $e) {
51+
fwrite(STDERR, "Error: Required table 'hm_user' does not exist in the database.\n" .
52+
"You may need to initialize the database structure first.\n" .
53+
"Run: php ./scripts/setup_database.php\n");
54+
exit(2);
55+
}
56+
} else {
57+
fwrite(STDERR, "Error: Unable to connect to the database.\n");
58+
exit(2);
59+
}
60+
4661
if ($user && $pass) {
4762
$auth->create($user, $pass);
4863
}

0 commit comments

Comments
 (0)