kingkay000 commited on
Commit
3963aef
·
verified ·
1 Parent(s): 4c38c62

Update easypay/db_config.php

Browse files
Files changed (1) hide show
  1. 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
- // Database credentials
8
- define('DB_HOST', 'o2.service.oyster.cloud76.cc:3306');
9
- define('DB_NAME', 'one_arps_aci');
10
- define('DB_USER', 'cs_admin');
11
- define('DB_PASS', 'D55-system-2-beasts-jungle-sky-birth');
12
- define('DB_CHARSET', 'utf8mb4');
 
 
13
 
14
- // PDO options - D55-system-2-beasts-jungle-sky-birth cs_admin
 
 
 
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
- // Create PDO instance
22
  try {
23
- $dsn = "mysql:host=" . DB_HOST . ";dbname=" . DB_NAME . ";charset=" . DB_CHARSET;
24
- $pdo = new PDO($dsn, DB_USER, DB_PASS, $options);
25
- } catch (PDOException $e) {
26
- die("Database connection failed: " . $e->getMessage());
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
+ }