fixed up router
This commit is contained in:
75
src/Database.php
Normal file
75
src/Database.php
Normal file
@@ -0,0 +1,75 @@
|
||||
<?php
|
||||
|
||||
class Database {
|
||||
|
||||
private $host;
|
||||
private $user;
|
||||
private $pass;
|
||||
private $dbname;
|
||||
private $conn;
|
||||
|
||||
public function __construct($dbinfo) {
|
||||
$this->host = $dbinfo['host'];
|
||||
$this->user = $dbinfo['user'];
|
||||
$this->pass = $dbinfo['pass'];
|
||||
$this->dbname = $dbinfo['name'];
|
||||
|
||||
$this->connect();
|
||||
}
|
||||
|
||||
private function connect() {
|
||||
$this->conn = new mysqli($this->host, $this->user, $this->pass, $this->dbname);
|
||||
|
||||
if ($this->conn->connect_error) {
|
||||
die("Connection failed: " . $this->conn->connect_error);
|
||||
}
|
||||
}
|
||||
|
||||
public function query($query) {
|
||||
$stmt = $this->conn->prepare($query);
|
||||
$stmt->execute();
|
||||
|
||||
return $stmt->get_result();
|
||||
}
|
||||
|
||||
public function getRow($query) {
|
||||
$result = $this->query($query);
|
||||
return $result->fetch_assoc();
|
||||
}
|
||||
|
||||
public function debugGetRow($query) {
|
||||
echo "<h1>Debug GetRow Query</h1>";
|
||||
echo "<div class='debug-query'>Query: $query</div>";
|
||||
$result = $this->query($query);
|
||||
$row = $result->fetch_assoc();
|
||||
|
||||
echo "<pre>";
|
||||
print_r($row);
|
||||
echo "</pre>";
|
||||
|
||||
die();
|
||||
}
|
||||
|
||||
public function getRows($query) {
|
||||
$result = $this->query($query);
|
||||
return $result->fetch_all(MYSQLI_ASSOC);
|
||||
}
|
||||
|
||||
public function debugGetRows($query) {
|
||||
echo "<h1>Debug GetRows Query</h1>";
|
||||
echo "<div class='debug-query'>Query: $query</div>";
|
||||
|
||||
$result = $this->query($query);
|
||||
$rows = $result->fetch_all(MYSQLI_ASSOC);
|
||||
|
||||
echo "<pre>";
|
||||
print_r($rows);
|
||||
echo "</pre>";
|
||||
|
||||
die();
|
||||
}
|
||||
|
||||
public function close() {
|
||||
$this->conn->close();
|
||||
}
|
||||
}
|
||||
Reference in New Issue
Block a user