update() public method

public update ( $table, $args ) : dibi\Fluent
return dibi\Fluent
Ejemplo n.º 1
0
 /**
  * @param $name
  * @param $params
  */
 public function saveContent($name, $params)
 {
     $names = $this->decodeNames($name);
     $locale = isset($params->locale) ? $params->locale : '';
     $rowId = $this->connection->select('id')->from(self::TABLE)->where(['namespace' => $names->namespace, 'name' => $names->name, 'locale' => $locale])->fetchSingle();
     $content = isset($params->content) ? $params->content : '';
     if ($rowId) {
         // update
         $this->connection->update(self::TABLE, ['content' => $content])->where(['id' => $rowId])->execute();
     } else {
         // new
         $this->connection->insert(self::TABLE, ['namespace' => $names->namespace, 'name' => $names->name, 'locale' => $locale, 'content' => $content])->execute();
     }
     $this->findContentAndFillCache($names->namespace, '', '');
 }
Ejemplo n.º 2
0
 /**
  * @param $item
  * @return \Dibi\Result|int
  */
 public function save($item)
 {
     if ($item->{$this->primaryKey}() === NULL) {
         $data = $this->itemToArray($item);
         try {
             $this->db->insert($this->tableName, $data)->execute();
             return $this->db->insertId();
         } catch (Exception $e) {
             Debugger::log(printf("An error has occurred: %s\n", $e->getMessage()), ILogger::ERROR);
             return NULL;
         }
     } else {
         $data = $this->itemToArray($item);
         try {
             $this->db->update($this->tableName, $data)->where($this->primaryKey . ' = %i', $item->{$this->primaryKey}())->execute();
             return $item->{$this->primaryKey}();
         } catch (ForeignKeyConstraintViolationException $e) {
             Debugger::log($e->getMessage(), ILogger::ERROR);
             return NULL;
         }
     }
 }
Ejemplo n.º 3
0
 /**
  * @param int $id
  * @param array $data
  * @return Dibi\Result|int
  */
 public function update($id, $data)
 {
     return $this->database->update($this->table, $data)->where('id = %i', $id)->execute();
 }