28 lines
720 B
PHP
28 lines
720 B
PHP
<?php
|
|
namespace Contabilidad\Implement\Database;
|
|
|
|
use Common\Alias\Database;
|
|
|
|
class MySQL extends Database
|
|
{
|
|
public function __construct(string $host, string $username, string $password, string $database_name, int $port = 3306)
|
|
{
|
|
$this->setHost($host, $port);
|
|
$this->setUser($username, $password);
|
|
$this->setName($database_name);
|
|
}
|
|
public function getDsn(): string
|
|
{
|
|
$dsn = ["mysql:host={$this->getHost()}"];
|
|
if ($this->getPort() !== 3306) {
|
|
$dsn []= "port={$this->getPort()}";
|
|
}
|
|
$dsn []= "dbname={$this->getName()}";
|
|
return implode(';', $dsn);
|
|
}
|
|
public function needsUser(): bool
|
|
{
|
|
return true;
|
|
}
|
|
}
|