/** * write * * @param string|int $id * @param string $data * * @return boolean */ public function write($id, $data) { $data = array($this->options['data_col'] => $data, $this->options['time_col'] => (int) time(), $this->options['id_col'] => $id); $data = (object) $data; $this->db->updateObject($this->options['table'], $data, $this->options['id_col']); if ($this->db->getAffectedRows()) { return true; } $this->db->insertObject($this->options['table'], $data, $this->options['id_col']); return true; }
/** * Do create action. * * @param mixed $dataset The data set contains data we want to store. * * @throws \Exception * @return mixed Data set data with inserted id. */ protected function doCreate($dataset) { $this->db->transactionStart(true); try { foreach ($dataset as &$data) { $entity = new Entity($this->getFields($this->table), $data); $pk = $this->getPrimaryKey(); $this->db->insertObject($this->table, $entity, $pk); $data->{$pk} = $entity->{$pk}; } } catch (\Exception $e) { $this->db->transactionRollback(true); throw $e; } $this->db->transactionCommit(true); return $dataset; }
/** * Method to store a row in the database from the AbstractDatabaseTable 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 * AbstractDatabaseTable instance. * * @param boolean $updateNulls True to update fields even if they are null. * * @return $this Method allows chaining * * @since 1.0 */ public function store($updateNulls = false) { // If a primary key exists update the object, otherwise insert it. if ($this->hasPrimaryKey()) { $this->db->updateObject($this->tableName, $this->tableFields, $this->tableKeys, $updateNulls); } else { $this->db->insertObject($this->tableName, $this->tableFields, $this->tableKeys[0]); } return $this; }