diff --git a/src/DatalayerTrait.php b/src/DatalayerTrait.php index ad0ed05..459a3d3 100755 --- a/src/DatalayerTrait.php +++ b/src/DatalayerTrait.php @@ -105,7 +105,7 @@ protected function setInstance(?PDO $pdo): self protected function getInstance(): PDO { - return $this->instance ?? $this->getConnect(); + return $this->getConnect(); } /** @@ -114,8 +114,17 @@ protected function getInstance(): PDO */ protected function setDatabase(string $database): self { - $this->database = $database; - $this->setInstance(null)->getInstance(); + if (strpos($_SERVER['SERVER_NAME'], mb_strtolower(CONFIG_DATA_LAYER["homologation"])) && !strpos($database, ucfirst(CONFIG_DATA_LAYER["homologation"]))) { + $database = $database.ucfirst(CONFIG_DATA_LAYER["homologation"] ?? ""); + $this->database = $database; + } else { + $this->database = $database; + } + + if (!empty($this->instance)){ + $this->executeSQL("USE {$this->getDatabase()}"); + } + return $this; }