exec($sql); echo "Table 'users' created successfully." . PHP_EOL; // Add or update the admin user $username = 'admin'; $email = 'admin@admin.com'; $password = '123'; $password_hash = password_hash($password, PASSWORD_DEFAULT); $role = 'admin'; $stmt = $pdo->prepare("SELECT COUNT(*) FROM users WHERE username = :username"); $stmt->execute([':username' => $username]); if ($stmt->fetchColumn() > 0) { // User exists, update password and email $update_sql = "UPDATE users SET password_hash = :password_hash, email = :email WHERE username = :username"; $update_stmt = $pdo->prepare($update_sql); $update_stmt->execute([ ':password_hash' => $password_hash, ':email' => $email, ':username' => $username ]); echo "Admin user updated with new password." . PHP_EOL; } else { // User does not exist, insert new admin user $insert_sql = " INSERT INTO users (username, email, password_hash, role) VALUES (:username, :email, :password_hash, :role); "; $insert_stmt = $pdo->prepare($insert_sql); $insert_stmt->execute([ ':username' => $username, ':email' => $email, ':password_hash' => $password_hash, ':role' => $role ]); echo "Default admin user created (admin / 123)." . PHP_EOL; } } catch (PDOException $e) { die("DB ERROR: " . $e->getMessage()); }