From 892537628a164e1cff7c1801f6770bb12730e3b5 Mon Sep 17 00:00:00 2001 From: lukibeg Date: Fri, 24 Oct 2025 23:21:05 -0300 Subject: [PATCH] UPDATE: Restructuring the ReportsModel to support .env variables. --- app/models/ReportsModel.php | 28 +++++++++++++++++++++------- 1 file changed, 21 insertions(+), 7 deletions(-) diff --git a/app/models/ReportsModel.php b/app/models/ReportsModel.php index 0686487..df3b1d1 100644 --- a/app/models/ReportsModel.php +++ b/app/models/ReportsModel.php @@ -4,20 +4,34 @@ namespace App\models; class ReportsModel { - private $hostname = 'produs.linepbx.com.br'; - private $username = 'produs-api'; - private $password = '*Ingline.Sys#9420%SECURITY#'; - private $database = 'qstats'; - private static $connection = null; - public function __construct() {} + private $hostname; + private $username; + private $password; + private $database; + private static $connection = null; + public function __construct() + { + + $this->hostname = $_ENV['DB_HOST']; + $this->username = $_ENV['DB_USER']; + $this->password = $_ENV['DB_PASSWORD']; + $this->database = $_ENV['DB']; + } public function dbConnect() { + if (self::$connection === null) { try { - self::$connection = new \PDO('mysql:host=produs.linepbx.com.br;dbname=qstats;charset=utf8mb4', $this->username, $this->password); + self::$connection = new \PDO( + 'mysql:host=' . $this->hostname . ';' . + 'dbname=' . $this->database . ';' . + 'charset=utf8mb4', + $this->username, + $this->password + ); self::$connection->setAttribute(\PDO::ATTR_ERRMODE, \PDO::ERRMODE_EXCEPTION); } catch (\PDOException $e) { return json_encode(['error' => 'Erro na conexão com o banco ' . $e->getMessage()]);