|
|
|
|
@@ -18,6 +18,7 @@ class Connection
|
|
|
|
|
private string $database;
|
|
|
|
|
private ?string $port;
|
|
|
|
|
private ?string $host;
|
|
|
|
|
private ?string $charset;
|
|
|
|
|
private string $error;
|
|
|
|
|
|
|
|
|
|
private function __construct($name, $config)
|
|
|
|
|
@@ -40,10 +41,11 @@ class Connection
|
|
|
|
|
$key = (strtolower(trim($this->name)));
|
|
|
|
|
$this->type = isset($config[$key]["TYPE"]) ? $config[$key]["TYPE"] : null;
|
|
|
|
|
$this->user = isset($config[$key]["USER"]) ? $config[$key]["USER"] : null;
|
|
|
|
|
$this->host = isset($config[$key]["HOST"]) ? $config[$config[$key]["HOST"]] : null;
|
|
|
|
|
$this->host = isset($config[$key]["HOST"]) ? $config[$key]["HOST"] : null;
|
|
|
|
|
$this->password = isset($config[$key]["PASSWORD"]) ? $config[$key]["PASSWORD"] : null;
|
|
|
|
|
$this->database = isset($config[$key]["DATABASE"]) ? $config[$key]["DATABASE"] : null;
|
|
|
|
|
$this->port = isset($config[$key]["PORT"]) ? $config[$key]["PORT"] : null;
|
|
|
|
|
$this->charset = isset($config[$key]["CHARSET"]) ? $config[$key]["CHARSET"] : null;
|
|
|
|
|
} catch (\Throwable $th) {
|
|
|
|
|
$this->error = $th->getMessage();
|
|
|
|
|
}
|
|
|
|
|
@@ -70,6 +72,7 @@ class Connection
|
|
|
|
|
$this->password = isset($_ENV[$this->getKey("PASSWORD", $key)]) ? $_ENV[$this->getKey("PASSWORD", $key)] : null;
|
|
|
|
|
$this->database = isset($_ENV[$this->getKey("DATABASE", $key)]) ? $_ENV[$this->getKey("DATABASE", $key)] : null;
|
|
|
|
|
$this->port = isset($_ENV[$this->getKey("PORT", $key)]) ? $_ENV[$this->getKey("PORT", $key)] : null;
|
|
|
|
|
$this->charset = isset($_ENV[$this->getKey("CHARSET", $key)]) ? $_ENV[$this->getKey("CHARSET", $key)] : null;
|
|
|
|
|
} catch (\Throwable $th) {
|
|
|
|
|
$this->error = $th->getMessage();
|
|
|
|
|
}
|
|
|
|
|
@@ -117,10 +120,19 @@ class Connection
|
|
|
|
|
return $stmt;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getMySQLOptions()
|
|
|
|
|
{
|
|
|
|
|
$ret = "";
|
|
|
|
|
if ($this->charset) {
|
|
|
|
|
$ret .= ";charset=" . $this->charset;
|
|
|
|
|
}
|
|
|
|
|
return $ret;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
private function getConnString()
|
|
|
|
|
{
|
|
|
|
|
$this->connstring = match ($this->type) {
|
|
|
|
|
"mysql" => "mysql:host=" . $this->host . ":" . $this->port . ";dbname=" . $this->database,
|
|
|
|
|
"mysql" => "mysql:host=" . $this->host . ":" . $this->port . ";dbname=" . $this->database . $this->getMySQLOptions() ,
|
|
|
|
|
"sqlite" => "sqlite:" . $this->database,
|
|
|
|
|
};
|
|
|
|
|
}
|
|
|
|
|
|