<?php
/**
 * AIMS - Agricultural Information and Market Linkage System
 * Database & Configuration
 * Student: Musumba Jonathan (21/BCS/010/UMC)
 */

// ============================================================================
//  config/database.php
// ============================================================================

class Database {
    private $host = "localhost";
    private $db_name = "aims_db";
    private $username = "root";
    private $password = "";
    public $conn;
    
    public function getConnection() {
        $this->conn = null;
        
        try {
            $this->conn = new PDO(
                "mysql:host=" . $this->host . ";dbname=" . $this->db_name . ";charset=utf8mb4",
                $this->username,
                $this->password,
                array(
                    PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
                    PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC,
                    PDO::ATTR_EMULATE_PREPARES => false
                )
            );
        } catch(PDOException $e) {
            die("Connection error: " . $e->getMessage());
        }
        
        return $this->conn;
    }
}
?>
