Beispiel #1
0
 public function update(Dbi_Model $query, array $data)
 {
     $components = $query->components();
     $update = new Dbi_Sql_Query_Update();
     $update->table($query->prefix() . $components['table']);
     foreach ($components['where'] as $where) {
         $orStatements = array();
         $orParameters = array();
         foreach ($where->expressions() as $or) {
             $orStatements[] = $or->statement();
             $orParameters = array_merge($orParameters, $or->parameters());
         }
         $args = array_merge(array(implode(' OR ', $orStatements)), $orParameters);
         call_user_func_array(array($update, 'where'), $args);
     }
     foreach ($data as $key => $value) {
         $update->set("`{$key}` = ?", $value);
     }
     $this->_execute($update);
 }
Beispiel #2
0
 public function update(Dbi_Model $query, array $data)
 {
     $components = $query->components();
     $update = new Dbi_Sql_Query_Update();
     $update->table($query->prefix() . $components['table']);
     foreach ($components['where'] as $where) {
         $orStatements = array();
         $orParameters = array();
         foreach ($where->expressions() as $or) {
             $orStatements[] = $or->statement();
             $orParameters = array_merge($orParameters, $or->parameters());
         }
         $args = array_merge(array(implode(' OR ', $orStatements)), $orParameters);
         call_user_func_array(array($update, 'where'), $args);
     }
     // Get rid of fields that are not defined in the schema.
     // TODO: Should undefined fields generate an error?
     /*foreach ($data as $key => $value) {
     			if (is_null($query->field($key))) {
     				unset($data[$key]);
     			} else {
     				// Convert arrays to JSON
     				// (Objects depend on __toString() for conversion)
     				if ( (is_array($value)) ) {
     					$data[$key] = json_encode($value);
     				}
     			}
     		}
     		$update->set($data);*/
     foreach ($data as $key => $value) {
         $update->set("`{$key}` = ?", $value);
     }
     //$this->_connection->query($update->query());
     $this->_execute($update, $query);
     if ($this->_connection->errno) {
         echo "{$update->query()}<br/>";
         throw new Exception($this->_connection->error);
     }
 }