Spaces:
Running
Running
Update easypay/db_config.php
Browse files- easypay/db_config.php +20 -15
easypay/db_config.php
CHANGED
|
@@ -1,27 +1,32 @@
|
|
| 1 |
<?php
|
| 2 |
/**
|
| 3 |
-
* Database Configuration
|
| 4 |
-
* PDO connection for one_arps_aci database
|
| 5 |
*/
|
| 6 |
|
| 7 |
-
//
|
| 8 |
-
|
| 9 |
-
|
| 10 |
-
|
| 11 |
-
|
| 12 |
-
|
|
|
|
|
|
|
| 13 |
|
| 14 |
-
//
|
|
|
|
|
|
|
|
|
|
| 15 |
$options = [
|
| 16 |
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
| 17 |
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
| 18 |
PDO::ATTR_EMULATE_PREPARES => false,
|
| 19 |
];
|
| 20 |
|
| 21 |
-
//
|
| 22 |
try {
|
| 23 |
-
$
|
| 24 |
-
|
| 25 |
-
|
| 26 |
-
|
| 27 |
-
|
|
|
|
|
|
| 1 |
<?php
|
| 2 |
/**
|
| 3 |
+
* Database Configuration using Hugging Face Secrets
|
|
|
|
| 4 |
*/
|
| 5 |
|
| 6 |
+
// 1. Map Hugging Face Secrets to PHP Variables
|
| 7 |
+
// The names inside getenv() must match the names you typed in the "Secrets" settings tab.
|
| 8 |
+
$host = getenv('DB_HOST');
|
| 9 |
+
$port = getenv('DB_PORT') ?: '3306'; // Default to 3306 if not set
|
| 10 |
+
$db = getenv('DB_NAME');
|
| 11 |
+
$user = getenv('DB_USER');
|
| 12 |
+
$pass = getenv('DB_PASS');
|
| 13 |
+
$charset = 'utf8mb4';
|
| 14 |
|
| 15 |
+
// 2. Set up the DSN (Data Source Name)
|
| 16 |
+
$dsn = "mysql:host=$host;port=$port;dbname=$db;charset=$charset";
|
| 17 |
+
|
| 18 |
+
// 3. PDO Options for security and error handling
|
| 19 |
$options = [
|
| 20 |
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
|
| 21 |
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
|
| 22 |
PDO::ATTR_EMULATE_PREPARES => false,
|
| 23 |
];
|
| 24 |
|
| 25 |
+
// 4. Establish the connection
|
| 26 |
try {
|
| 27 |
+
$pdo = new PDO($dsn, $user, $pass, $options);
|
| 28 |
+
} catch (\PDOException $e) {
|
| 29 |
+
// Log error and stop execution
|
| 30 |
+
error_log($e->getMessage());
|
| 31 |
+
die("Error: Could not connect to the database. Check Hugging Face Logs.");
|
| 32 |
+
}
|