diff --git a/include/class.orm.php b/include/class.orm.php index 4b63be4a45ebc21bfbefbe61d4d0737f423149ba..de47d422ecf6b2290e8541b5476d2a54f1d3cdbb 100644 --- a/include/class.orm.php +++ b/include/class.orm.php @@ -147,7 +147,7 @@ class VerySimpleModel { foreach ($pk as $p) $filter[] = $p.' = '.db_input($this->get($p)); $sql .= ' WHERE '.implode(' AND ', $filter).' LIMIT 1'; - return db_affected_rows(db_query($sql)) == 1; + return db_query($sql) && db_affected_rows() == 1; } function save($refetch=false) { @@ -173,10 +173,8 @@ class VerySimpleModel { $sql .= ' WHERE '.implode(' AND ', $filter); $sql .= ' LIMIT 1'; } - if (db_affected_rows(db_query($sql)) != 1) { + if (!db_query($sql) || db_affected_rows() != 1) throw new Exception(db_error()); - return false; - } if ($this->__new__) { if (count($pk) == 1) $this->ht[$pk[0]] = db_insert_id(); @@ -433,17 +431,22 @@ class FlatArrayIterator extends ModelInstanceIterator { class InstrumentedList extends ModelInstanceIterator { var $key; var $id; + var $model; function __construct($fkey, $queryset=false) { list($model, $this->key, $this->id) = $fkey; if (!$queryset) $queryset = $model::objects()->filter(array($this->key=>$this->id)); parent::__construct($queryset); + $this->model = $model; if (!$this->id) $this->resource = null; } function add($object) { + if (!$object || !$object instanceof $this->model) + throw new Exception('Attempting to add invalid object to list'); + $object->{$this->key} = $this->id; $object->save(); $this->list[] = $object; diff --git a/include/mysqli.php b/include/mysqli.php index 7d765b428ac35b350dc9c9f4dd58f3e6b22af5c7..34fa57479b64ebcda7e1ac381f4c70a6069773aa 100644 --- a/include/mysqli.php +++ b/include/mysqli.php @@ -60,6 +60,7 @@ function db_connect($host, $user, $passwd, $options = array()) { @$__db->query('SET NAMES "utf8"'); @$__db->query('SET CHARACTER SET "utf8"'); @$__db->query('SET COLLATION_CONNECTION=utf8_general_ci'); + $__db->set_charset('utf8'); @db_set_variable('sql_mode', '');