Update database.php

This commit is contained in:
ssbg04 authored and GitHub committed 2025-06-23 22:54:51 +08:00
1 parent 26cb03166f
commit 1ba8ac7b83
1 file changed
+11
+11
View File
@@ -1,13 +1,24 @@
<?php
// Load environment variables from Railway
$host = getenv("MYSQLHOST");
$user = getenv("MYSQLUSER");
$password = getenv("MYSQLPASSWORD");
$database = getenv("MYSQLDATABASE");
$port = getenv("MYSQLPORT");
// Fallback if any variable is missing (optional but helpful)
if (!$host || !$user || !$password || !$database || !$port) {
die("Missing required database environment variables.");
}
// Create MySQL connection
$conn = new mysqli($host, $user, $password, $database, (int)$port);
// Check connection
if ($conn->connect_error) {
die("Connection failed: " . $conn->connect_error);
}
// Optional: success message
// echo "Connected to Railway MySQL successfully!";
?>