80 lines
2.3 KiB
PHP
80 lines
2.3 KiB
PHP
<?php
|
|
|
|
namespace app\config;
|
|
|
|
|
|
use Illuminate\Database\Connection;
|
|
use support\Db;
|
|
|
|
class DatabaseConfig
|
|
{
|
|
public string $host = 'localhost' {
|
|
get => $this->host;
|
|
}
|
|
public string $username = 'root' {
|
|
get => $this->username;
|
|
}
|
|
public string $password = '' {
|
|
get => $this->password;
|
|
}
|
|
public string $database = 'ds2' {
|
|
get => $this->database;
|
|
}
|
|
public int $port = 3306{
|
|
get => $this->port;
|
|
}
|
|
|
|
public string $charset = 'utf8mb4'{
|
|
get => $this->charset;
|
|
}
|
|
//collation
|
|
public string $collation = 'utf8mb4_general_ci'{
|
|
get => $this->collation;
|
|
}
|
|
//driver
|
|
public string $driver = 'mysql'{
|
|
get => $this->driver;
|
|
}
|
|
|
|
public int $max_connections = 5{
|
|
get => $this->max_connections;
|
|
}
|
|
public int $min_connections = 1{
|
|
get => $this->min_connections;
|
|
}
|
|
public int $wait_timeout = 3{
|
|
get => $this->wait_timeout;
|
|
}
|
|
public int $idle_timeout = 60{
|
|
get => $this->idle_timeout;
|
|
}
|
|
public int $heartbeat_interval = 50{
|
|
get => $this->heartbeat_interval;
|
|
}
|
|
|
|
public function __construct()
|
|
{
|
|
$this->host = getenv('DB_HOST', $this->host);
|
|
$this->username = getenv('DB_USER', $this->username);
|
|
$this->password = getenv('DB_PASSWORD', $this->password);
|
|
$this->database = getenv('DB_NAME', $this->database);
|
|
$this->port = getenv('DB_PORT', $this->port);
|
|
$this->charset = getenv('DB_CHARSET', $this->charset);
|
|
$this->collation = getenv('DB_COLLATION', $this->collation);
|
|
$this->driver = getenv('DB_DRIVER', $this->driver);
|
|
$this->max_connections = getenv('DB_MAX_CONNECTIONS', $this->max_connections);
|
|
$this->min_connections = getenv('DB_MIN_CONNECTIONS', $this->min_connections);
|
|
$this->wait_timeout = getenv('DB_WAIT_TIMEOUT', $this->wait_timeout);
|
|
$this->idle_timeout = getenv('DB_IDLE_TIMEOUT', $this->idle_timeout);
|
|
$this->heartbeat_interval = getenv('DB_HEARTBEAT_INTERVAL', $this->heartbeat_interval);
|
|
}
|
|
|
|
/**
|
|
* @param $connection string|null
|
|
* @return Connection
|
|
*/
|
|
public function getConnection(?string $connection = null): Connection
|
|
{
|
|
return Db::connection($connection);
|
|
}
|
|
} |