/** * セッションのデータををDBから読み込む. * * @param string $id セッションID * @return string セッションデータの値 */ function read($id) { $id_key = $this->id_key; $data_key = $this->data_key; // セッションデータを取得する。 $select = new Vizualizer_Query_Select($this->table); $select->addColumn($this->table->_W); $select->addWhere($this->table->{$id_key} . " = ?", array($id)); $result = $select->execute(); return $result[0][$data_key]; }
/** * 指定したトランザクション内にて主キーベースでデータの保存を行う。 * 主キーが存在しない場合は何もしない。 * また、モデル内のカラムがDBに無い場合はスキップする。 * データ作成日/更新日は自動的に設定される。 */ public function save() { if (!empty($this->primary_keys)) { // 現在該当のデータが登録されているか調べる。 $pkset = false; $select = new Vizualizer_Query_Select($this->access); $select->addColumn($this->access->_W); foreach ($this->primary_keys as $key) { if (isset($this->values[$key])) { $select->addWhere($this->access->{$key} . " = ?", array($this->values[$key])); } else { $pkset = false; break; } $pkset = true; } if ($pkset) { $result = $select->execute(); } else { $result = array(); } if (!is_array($result) || empty($result)) { // 主キーのデータが無かった場合はデータを作成する。 $this->create(); } else { // 主キーのデータがあった場合はデータを更新する。 $this->update(); } } }