aboutsummaryrefslogtreecommitdiffstats
path: root/MainDb.php
diff options
context:
space:
mode:
authorFilipp Lepalaan <filipp@mac.com>2010-09-01 18:28:32 +0300
committerFilipp Lepalaan <filipp@mac.com>2010-09-01 18:28:32 +0300
commitf9777c989ce04d33288655ea4d1c274bd5b90b5f (patch)
treeb2a04f33a07516e1d16095031d30def81b57cf0d /MainDb.php
parentdead03e955367d4635764251f62256365c01b221 (diff)
downloadmain-f9777c989ce04d33288655ea4d1c274bd5b90b5f.tar.gz
main-f9777c989ce04d33288655ea4d1c274bd5b90b5f.tar.bz2
main-f9777c989ce04d33288655ea4d1c274bd5b90b5f.zip
return row count on delete
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'];
+ }
}