27 lines
563 B
PHP
27 lines
563 B
PHP
<?php
|
|
|
|
namespace php;
|
|
|
|
use PDO;
|
|
|
|
|
|
/**
|
|
* Helper class for interacting with the database.
|
|
*/
|
|
class Database
|
|
{
|
|
/**
|
|
* Opens a connection with the database at `filename`.
|
|
*
|
|
* @param string $filename the path to the database to connect to
|
|
* @return PDO a PDO object that connects with the database
|
|
*/
|
|
public static function connect(string $filename): PDO
|
|
{
|
|
return new PDO("sqlite:$filename", options: array(PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION));
|
|
}
|
|
|
|
|
|
// TODO: Add version number, etc., and auto-migration
|
|
}
|