Exemplo n.º 1
0
 /**
  * write
  *
  * @param string|int $id
  * @param string     $data
  *
  * @return  boolean
  */
 public function write($id, $data)
 {
     $writer = $this->db->getWriter();
     $data = array($this->options['data_col'] => $data, $this->options['time_col'] => (int) time(), $this->options['id_col'] => $id);
     $writer->updateOne($this->options['table'], $data, $this->options['id_col']);
     if ($writer->countAffected()) {
         return true;
     }
     $writer->insertOne($this->options['table'], $data, $this->options['id_col']);
     return true;
 }
Exemplo n.º 2
0
 /**
  * Method to store a row in the database from the AbstractTable instance properties.
  * If a primary key value is set the row with that primary key value will be
  * updated with the instance property values.  If no primary key value is set
  * a new row will be inserted into the database with the properties from the
  * AbstractTable instance.
  *
  * @param   boolean  $updateNulls  True to update fields even if they are null.
  *
  * @return  $this  Method allows chaining
  *
  * @since   2.0
  */
 public function store($updateNulls = false)
 {
     // If a primary key exists update the object, otherwise insert it.
     if ($this->hasPrimaryKey()) {
         $this->db->getWriter()->updateOne($this->table, $this->data, $this->keys, $updateNulls);
     } else {
         $this->db->getWriter()->insertOne($this->table, $this->data, $this->keys[0]);
     }
     return $this;
 }