add simrs supporting functions

This commit is contained in:
renaldybrada
2026-03-13 11:03:53 +07:00
parent ee4129aec4
commit 9745454134
2 changed files with 94 additions and 0 deletions
+57
View File
@@ -0,0 +1,57 @@
<?php
class PostgresDb
{
private $pdo;
public function __construct()
{
$host = "10.10.123.238";
$port = "5432";
$dbname = "simrs";
$user = "brawijaya";
$password = "ub*2025";
$dsn = "pgsql:host=$host;port=$port;dbname=$dbname";
try {
$this->pdo = new PDO($dsn, $user, $password, [
PDO::ATTR_ERRMODE => PDO::ERRMODE_EXCEPTION,
PDO::ATTR_DEFAULT_FETCH_MODE => PDO::FETCH_ASSOC
]);
} catch (PDOException $e) {
die("Database connection failed: " . $e->getMessage());
}
}
public function query($sql, $params = [])
{
$stmt = $this->pdo->prepare($sql);
$stmt->execute($params);
return $stmt;
}
public function fetchAll($sql, $params = [])
{
return $this->query($sql, $params)->fetchAll();
}
public function fetch($sql, $params = [])
{
return $this->query($sql, $params)->fetch();
}
public function lastInsertId()
{
return $this->pdo->lastInsertId();
}
}