<?php

/**
 * Legacy DB_CONNECT class — retained for backward compatibility.
 * Delegates to DatabaseManager instead of opening independent connections.
 */
class DB_CONNECT
{
    /** @var \PgSql\Connection|null */
    private $con = null;

    function __construct()
    {
        require_once __DIR__ . '/DatabaseManager.php';
        $this->con = DatabaseManager::getInstance()->getConnection();
    }

    function __destruct()
    {
        require_once __DIR__ . '/db_helpers.php';
        mch_db_release($this->con);
    }

    /**
     * @return \PgSql\Connection PostgreSQL connection
     */
    function connect()
    {
        if ($this->con === null) {
            $this->con = DatabaseManager::getInstance()->getConnection();
        }
        return $this->con;
    }

    function close()
    {
        require_once __DIR__ . '/db_helpers.php';
        mch_db_release($this->con);
        $this->con = null;
    }
}

?>
