aboutsummaryrefslogtreecommitdiffstats
path: root/MainDb.php
diff options
context:
space:
mode:
Diffstat (limited to 'MainDb.php')
-rw-r--r--MainDb.php17
1 files changed, 16 insertions, 1 deletions
diff --git a/MainDb.php b/MainDb.php
index f26527d..6a18f9e 100644
--- a/MainDb.php
+++ b/MainDb.php
@@ -103,7 +103,12 @@ class MainDb
return MainApp::error($error);
}
- // select statements need the query results
+ // DELETE statements should report number of rows
+ if (preg_match('/^DELETE/i', $sql)) {
+ return $result->rowCount();
+ }
+
+ // SELECT statements need the query results
if (preg_match('/^SELECT/i', $sql)) {
return $stmt;
}
@@ -147,6 +152,16 @@ class MainDb
$stmt = self::query($sql, $args) or exit(MainApp::error('Error executing query '.$sql));
return $stmt->fetchAll(PDO::FETCH_ASSOC);
}
+
+ ////
+ // count something
+ public static function total($table)
+ {
+ $sql = 'SELECT COUNT(*) AS the_count FROM `%s`';
+ $res = self::fetch(sprintf($sql, $table));
+ $res = current($res);
+ return $res['the_count'];
+ }
}