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

Upload db_config.php

Browse files
Files changed (1) hide show
  1. bank-credit-update/db_config.php +32 -0
bank-credit-update/db_config.php ADDED
@@ -0,0 +1,32 @@
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
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
+ }