Files
Ecobuddy/Models/Database.php
boris 4005328979 erm did a small amount
output database to view
added basic filters
improve bootstrap theming and positioning
added pagination
2024-11-28 23:40:06 +00:00

37 lines
957 B
PHP

<?php
class Database {
/**
* @var Database
*/
protected static $_dbInstance = null;
/**
* @var PDO
*/
protected $_dbHandle;
public function getDbConnection(): PDO
{
return $this->_dbHandle;
}
public static function getInstance(): ?Database
{
if(self::$_dbInstance == null) {
self::$_dbInstance = new self();
}
return self::$_dbInstance;
}
private function __construct() {
try {
$this->_dbHandle = new PDO("sqlite:Databases/ecobuddy.sqlite");
$this->_dbHandle->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$this->_dbHandle->setAttribute(PDO::ATTR_EMULATE_PREPARES, false);
}
catch (PDOException $e) {
echo $e->getMessage();
}
}
public function __destruct() {
$this->_dbHandle = null; // destroys the PDO handle when no longer needed
}
}