From 0c98677b7d403cdf429423887f691c9ddf767b5a Mon Sep 17 00:00:00 2001 From: akulikov Date: Mon, 27 Apr 2009 22:10:35 +0000 Subject: [PATCH] insert standart git-svn-id: svn+ssh://code.netmonsters.ru/svn/majestic/trunk@82 4cb57b5f-5bbd-dd11-951b-001d605cbbc5 --- classes/Model.class.php | 9 ++++++--- 1 file changed, 6 insertions(+), 3 deletions(-) diff --git a/classes/Model.class.php b/classes/Model.class.php index 0a767b7..eabd935 100644 --- a/classes/Model.class.php +++ b/classes/Model.class.php @@ -96,11 +96,14 @@ abstract class Model function insert($data, $postfix = '') { - $sql = ''; + $keys = array(); + $values = array(); + foreach ($data as $key => $val) { - $sql .= $key.'="'.$this->escape($val).'", '; + $keys[] = $key; + $values[] = $this->escape($val); } - return $this->query('INSERT '.$this->table.' SET '.rtrim($sql, ', ').' '.$postfix); + return $this->query('INSERT INTO '.$this->table.' ('.implode(',', $keys).") VALUES('".implode("','", $values)."') ".$postfix); } function delete($id)