1
0
This repository has been archived on 2025-03-31. You can view files and clone it, but cannot push or open issues or pull requests.
php-owntracks-recorder/lib/db/SQLite.php
tomyvi 41415d1cb2 Abstraction of recorder
Abstraction of recorder to offer alternative to Owntracks
2018-11-11 22:03:55 +01:00

44 lines
1.0 KiB
PHP
Executable File

<?php
require_once(__DIR__ . '/AbstractDb.php');
class SQLite extends AbstractDb
{
public function __construct($db, $hostname = null, $username = null, $password = null, $prefix = '')
{
$this->db = new \PDO('sqlite:' . $db);
$this->prefix = '';
}
protected function query(string $sql, array $params): array
{
$stmt = $this->db->prepare($sql);
if (!$stmt) {
return false;
}
$stmt->execute($params);
$result = array();
while ($data = $stmt->fetch(\PDO::FETCH_ASSOC)) {
// Loop through results here $data[]
$result[] = $data;
}
$stmt->closeCursor();
return $result;
}
protected function execute(string $sql, array $params): bool
{
$stmt = $this->db->prepare($sql);
if (!$stmt) {
return false;
}
$result = $stmt->execute($params);
if ($result) {
$stmt->closeCursor();
}
return $result;
}
}