123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051 |
- <?php
- namespace inter\storage\mysql;
- use Exception;
- class Config
- {
- private string $host;
- private string $port;
- private string $user;
- private string $password;
- private string $database;
- public function __construct(string $host, string $port, string $user, string $password, string $database)
- {
- if ($host == "") {
- throw new Exception("数据库连接host为空");
- }
- if ($user == "") {
- throw new Exception("数据库用户为空");
- }
- if ($password == "") {
- throw new Exception("数据库密码为空");
- }
- if ($database == "") {
- throw new Exception("数据库名字为空");
- }
- $this->host = $host;
- $this->port = $port;
- $this->user = $user;
- $this->password = $password;
- $this->database = $database;
- }
- public function GetPdoDSN(): string
- {
- return "mysql:host={$this->host}" . (empty($this->port) ? "" : ":{$this->port}") . ";dbname={$this->database}";
- }
- public function GetUser(): string
- {
- return $this->user;
- }
- public function GetPassword(): string
- {
- return $this->password;
- }
- }
|