CDbHttpSession - setSessionItem(id,key,val)?

I am planing to use the following method to set a session key. Is there better/preferred way?




      public function setSessionItem($id,$key,$val) {

        $expire=time()+$this->getTimeout();

        $db=$this->getDbConnection();

        $sql="SELECT id FROM {$this->sessionTableName} WHERE id=:id";

        if($db->createCommand($sql)->bindValue(':id',$id)->queryScalar()===false)

            $sql="INSERT INTO {$this->sessionTableName} (id, $key, expire) VALUES (:id, :val, $expire)";

        else 

            $sql="UPDATE {$this->sessionTableName} SET $key=:$val, expire=$expire WHERE id = :id";

        $db->createCommand($sql)->bindValue(':id',$id)->bindValue(':val',$val)->execute();

        return true;

    }



I don’t understand. What is the additional key for? What are you trying to do?

Good question, my session table has additional columns, broker, token, regen_sid etc. And they get updated at different point of time as well.

Okay I see. I think it’s fine the way you did. However did you thought about adding the info to CWebUser instead of CHttpSession? Just a hint, maybe you really need session in this case, I don’t know your application =)