From 2aeaedc2efc827508e4ed324f20c116bf486cfbd Mon Sep 17 00:00:00 2001 From: pzinovkin Date: Wed, 17 Mar 2010 20:52:23 +0000 Subject: [PATCH] FetchColumn method, #16 git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/branches/evo@132 4cb57b5f-5bbd-dd11-951b-001d605cbbc5 --- model/DbStatement.php | 12 ++++++++++++ model/Model.php | 6 ++++-- 2 files changed, 16 insertions(+), 2 deletions(-) diff --git a/model/DbStatement.php b/model/DbStatement.php index 30e1142..0386c24 100644 --- a/model/DbStatement.php +++ b/model/DbStatement.php @@ -130,6 +130,18 @@ abstract class DbStatement /** * @param string $field */ + public function fetchColumn($field) + { + $data = array(); + while ($row = $this->fetch(Db::FETCH_ASSOC)) { + $data[] = $row[$field]; + } + return $data; + } + + /** + * @param string $field + */ public function fetchField($field) { $row = $this->fetch(Db::FETCH_ASSOC); diff --git a/model/Model.php b/model/Model.php index 49e7de4..e255a02 100644 --- a/model/Model.php +++ b/model/Model.php @@ -117,12 +117,14 @@ abstract class Model implements iCacheable } /** - * @param mixed $where + * @param int|array $where Int or array ids * @return int Number of affected rows */ public function delete($where) { - if (is_int($where)) { + if (is_array($where)) { + $where = $this->identify($this->key) . ' IN (' . $this->quote($where) . ')'; + } else { $where = $this->identify($this->key) . '=' . (int) $where; } return $this->db->delete($this->table(false), $where);