MySQL Engine

This commit is contained in:
2021-10-13 22:46:32 -03:00
parent 68122d1431
commit 50bd59498d

32
src/MySQL.php Normal file
View File

@ -0,0 +1,32 @@
<?php
namespace ProVM\Database;
use ProVM\Common\Define\Engine;
class MySQL implements Engine {
protected $host;
protected $name;
public function __construct(string $host, string $name, ?int $port = null) {
$host_arr = [
'name' => $host
];
if ($port !== null) {
$host_arr['port'] = $port;
}
$this->host = (object) $host_arr;
$this->name = $name;
}
public function dsn(): string {
$dsn = [
'host=' . $this->host->name
];
if (isset($this->host->port)) {
$dsn []= 'port=' . $this->host->port;
}
$dsn []= 'dbname=' . $this->name;
return 'mysql:' . implode(';', $dsn);
}
public function hasLogin(): bool {
return true;
}
}