diff --git a/db.class.php b/db.class.php index f8e375e..7d3288d 100644 --- a/db.class.php +++ b/db.class.php @@ -473,8 +473,13 @@ class MeekroDB { protected function escape($str) { return "'" . $this->get()->real_escape_string(strval($str)) . "'"; } protected function sanitize($value) { - if (is_object($value) && ($value instanceof MeekroDBEval)) return $value->text; - else if (is_null($value)) return $this->usenull ? 'NULL' : "''"; + if (is_object($value)) { + if ($value instanceof MeekroDBEval) return $value->text; + else if ($value instanceof DateTime) return $this->escape($value->format('Y-m-d H:i:s')); + else return ''; + } + + if (is_null($value)) return $this->usenull ? 'NULL' : "''"; else if (is_bool($value)) return ($value ? 1 : 0); else if (is_int($value)) return $value; else if (is_float($value)) return $value; diff --git a/simpletest/BasicTest.php b/simpletest/BasicTest.php index 9e4788e..ad153c3 100644 --- a/simpletest/BasicTest.php +++ b/simpletest/BasicTest.php @@ -142,7 +142,9 @@ class BasicTest extends SimpleTest { } function test_4_query() { - DB::query("UPDATE %b SET birthday=%t WHERE username=%s", 'accounts', new DateTime('10 September 2000 13:13:13'), 'Charlie\'s Friend'); + DB::update('accounts', array( + 'birthday' => new DateTime('10 September 2000 13:13:13') + ), 'username=%s', 'Charlie\'s Friend'); $results = DB::query("SELECT * FROM accounts WHERE username=%s AND birthday IN %lt", 'Charlie\'s Friend', array('September 10 2000 13:13:13')); $this->assert(count($results) === 1);