/** * Executes query and returns a single row of result. * @param Connection $db the DB connection used to create the DB command. * If null, the DB connection returned by [[modelClass]] will be used. * @return ActiveRecord|array|null a single row of query result. Depending on the setting of [[asArray]], * the query result may be either an array or an ActiveRecord object. Null will be returned * if the query results in nothing. */ public function one($db = null) { $row = parent::one($db); if ($row !== false) { $models = $this->populate([$row]); return reset($models) ?: null; } else { return null; } }
/** * Session read handler. * Do not call this method directly. * @param string $id session ID * @return string the session data */ public function readSession($id) { $query = new Query(); $query->from($this->sessionTable)->where('[[expire]]>:expire AND [[id]]=:id', [':expire' => time(), ':id' => $id]); if (isset($this->readCallback)) { $fields = $query->one($this->db); return $fields === false ? '' : $this->extractData($fields); } $data = $query->select(['data'])->scalar($this->db); return $data === false ? '' : $data; }