summaryrefslogtreecommitdiffstats
path: root/app/class/table.class.php
diff options
context:
space:
mode:
authorMalf Furious <m@lfurio.us>2017-02-06 01:18:10 -0500
committerMalf Furious <m@lfurio.us>2017-02-06 01:18:10 -0500
commit476192ca8fa2053af74a7e7f5e4006c83c8d0cad (patch)
tree69c73b211da59924a19a89d45e45d1e9692b5385 /app/class/table.class.php
parent56a6dda13bb85b25f590fc8a64535bb53c3c2fd2 (diff)
downloadscrott-476192ca8fa2053af74a7e7f5e4006c83c8d0cad.tar.gz
scrott-476192ca8fa2053af74a7e7f5e4006c83c8d0cad.zip
Update table class tree to use static database references
Diffstat (limited to '')
-rw-r--r--app/class/table.class.php44
1 files changed, 20 insertions, 24 deletions
diff --git a/app/class/table.class.php b/app/class/table.class.php
index be7a375..0b9a53c 100644
--- a/app/class/table.class.php
+++ b/app/class/table.class.php
@@ -29,8 +29,6 @@ abstract class table
*/
protected $fields = array();
- protected $db;
-
/*
* Instanciate an object representing an existing database entity
* named by the given GUID. If no such GUID exists, an exception
@@ -39,8 +37,6 @@ abstract class table
*/
public function __construct(?string $guid = NULL)
{
- $this->db = database::getInstance();
-
if ($guid)
$this->loadObj($guid);
}
@@ -52,16 +48,16 @@ abstract class table
*/
private function loadObj(string $guid) : void
{
- $guid = $this->db->esc($guid);
+ $guid = database::esc($guid);
if (!$this->isGUID($guid))
throw new Exception("GUID " . $guid . " does not exist");
foreach ($this->fields as $tbl => $flds)
{
- $tbl = $this->db->esc($tbl);
+ $tbl = database::esc($tbl);
$query = "SELECT * FROM " . $tbl . " WHERE guid = '" . $guid . "'";
- $res = $this->db->query($query)[0];
+ $res = database::query($query)[0];
foreach ($flds as $fld)
{
@@ -85,7 +81,7 @@ abstract class table
foreach ($this->fields as $tbl => $flds)
{
- $tbl = $this->db->esc($tbl);
+ $tbl = database::esc($tbl);
$udstr = "";
foreach ($flds as $fld)
@@ -93,15 +89,15 @@ abstract class table
if (!isset($this->$fld))
continue;
- $fld = $this->db->esc($fld);
- $udstr .= $fld . " = '" . $this->db->esc($this->$fld) . "', ";
+ $fld = database::esc($fld);
+ $udstr .= $fld . " = '" . database::esc($this->$fld) . "', ";
}
if (strlen($udstr) > 0)
{
$udstr = substr($udstr, 0, -2); // remove ", " from the end
- $query = "UPDATE " . $tbl . " SET " . $udstr . " WHERE guid = '" . $this->db->esc($this->guid) . "'";
- $this->db->query($query);
+ $query = "UPDATE " . $tbl . " SET " . $udstr . " WHERE guid = '" . database::esc($this->guid) . "'";
+ database::query($query);
}
}
}
@@ -115,7 +111,7 @@ abstract class table
foreach ($this->fields as $tbl => $flds)
{
- $tbl = $this->db->esc($tbl);
+ $tbl = database::esc($tbl);
$fldstr = "";
$valstr = "";
@@ -124,9 +120,9 @@ abstract class table
if (!isset($this->$fld))
continue;
- $fld = $this->db->esc($fld);
+ $fld = database::esc($fld);
$fldstr .= $fld . ", ";
- $valstr .= "'" . $this->db->esc($this->$fld) . "', ";
+ $valstr .= "'" . database::esc($this->$fld) . "', ";
}
if (strlen($fldstr) > 0)
@@ -134,7 +130,7 @@ abstract class table
$fldstr = substr($fldstr, 0, -2); // remove ", "
$valstr = substr($valstr, 0, -2);
$query = "INSERT INTO " . $tbl . " (" . $fldstr . ") VALUES (" . $valstr . ")";
- $this->db->query($query);
+ database::query($query);
}
}
}
@@ -150,21 +146,21 @@ abstract class table
if (!isset($this->guid))
throw new Exception("GUID (null) does not exist");
- $guid = $this->db->esc($this->guid);
+ $guid = database::esc($this->guid);
foreach ($this->fields as $tbl => $flds)
{
- $tbl = $this->db->esc($tbl);
+ $tbl = database::esc($tbl);
$query = "DELETE FROM " . $tbl . " WHERE guid = '" . $guid . "'";
- $this->db->query($query);
+ database::query($query);
}
/* garbage collection */
$query = "DELETE FROM members WHERE guid = '" . $guid . "' OR member = '" . $guid . "'";
- $this->db->query($query);
+ database::query($query);
$query = "DELETE FROM views WHERE guid = '" . $guid . "' OR viewer = '" . $guid . "'";
- $this->db->query($query);
+ database::query($query);
}
/*
@@ -181,7 +177,7 @@ abstract class table
private function getCurrentTimestamp() : string
{
$query = "SELECT now() AS stamp";
- $res = $this->db->query($query);
+ $res = database::query($query);
return $res[0]['stamp'];
}
@@ -190,9 +186,9 @@ abstract class table
*/
private function isGUID(string $guid) : bool
{
- $guid = $this->db->esc($guid);
+ $guid = database::esc($guid);
$query = "SELECT guid FROM objects WHERE guid = '" . $guid . "'";
- $res = $this->db->query($query);
+ $res = database::query($query);
return count($res) > 0;
}