mirror of
https://github.com/YGGverse/Yoda.git
synced 2026-04-01 09:05:27 +00:00
init database constructor
This commit is contained in:
parent
7ac9260ba7
commit
2053ab01de
5 changed files with 71 additions and 5 deletions
|
|
@ -6,6 +6,52 @@ namespace Yggverse\Yoda\Model;
|
|||
|
||||
class Database
|
||||
{
|
||||
public function __construct()
|
||||
{}
|
||||
public \PDO $database;
|
||||
|
||||
public function __construct(
|
||||
string $database,
|
||||
?string $username = null,
|
||||
?string $password = null
|
||||
) {
|
||||
try
|
||||
{
|
||||
$this->database = new \PDO(
|
||||
sprintf(
|
||||
'sqlite:%s',
|
||||
$database
|
||||
),
|
||||
$username,
|
||||
$password
|
||||
);
|
||||
|
||||
$this->database->setAttribute(
|
||||
\PDO::ATTR_ERRMODE,
|
||||
\PDO::ERRMODE_EXCEPTION
|
||||
);
|
||||
|
||||
$this->database->setAttribute(
|
||||
\PDO::ATTR_DEFAULT_FETCH_MODE,
|
||||
\PDO::FETCH_OBJ
|
||||
);
|
||||
|
||||
$this->database->query('
|
||||
CREATE TABLE IF NOT EXISTS "history"
|
||||
(
|
||||
"id" INTEGER PRIMARY KEY AUTOINCREMENT NOT NULL,
|
||||
"time" INTEGER NOT NULL,
|
||||
"address" VARCHAR(1024) NOT NULL
|
||||
)
|
||||
');
|
||||
}
|
||||
|
||||
catch (\PDOException $exception)
|
||||
{
|
||||
exit(
|
||||
print_r(
|
||||
$exception->getMessage(),
|
||||
true
|
||||
)
|
||||
);
|
||||
}
|
||||
}
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue