MySQL Engine
This commit is contained in:
32
src/MySQL.php
Normal file
32
src/MySQL.php
Normal 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;
|
||||||
|
}
|
||||||
|
}
|
Reference in New Issue
Block a user