diff options
author | Filipp Lepalaan <filipp@mac.com> | 2010-09-01 18:28:32 +0300 |
---|---|---|
committer | Filipp Lepalaan <filipp@mac.com> | 2010-09-01 18:28:32 +0300 |
commit | f9777c989ce04d33288655ea4d1c274bd5b90b5f (patch) | |
tree | b2a04f33a07516e1d16095031d30def81b57cf0d /MainDb.php | |
parent | dead03e955367d4635764251f62256365c01b221 (diff) | |
download | main-f9777c989ce04d33288655ea4d1c274bd5b90b5f.tar.gz main-f9777c989ce04d33288655ea4d1c274bd5b90b5f.tar.bz2 main-f9777c989ce04d33288655ea4d1c274bd5b90b5f.zip |
return row count on delete
Diffstat (limited to 'MainDb.php')
-rw-r--r-- | MainDb.php | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -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']; + } } |