Session Not Working Correctly In Yii

I am using sessions in when usercontroller actionlogin


$userid=User::model()->fetch($username,$password);

            //  var_dump($userid);

             Yii::app()->SESSION['srid']=$userid;

in user model i have


public function fetch($username,$password)

{


    $sql="select id FROM user where ( username='".$username. "' AND password='".$password."')";

    $connection=Yii::app()->db;

    $command=$connection->createCommand($sql);

    $resuserid=$command->queryAll();

    //var_dump($resuserid);

    $result=array();

    foreach($resuserid as $key=>$val)

    {$result[]=$val;}

    return $result;

    }

when i access this in some other controller

person personcontroller

i need to stored the


$model->personid=Yii::app()->SESSION['srid'];

the result of


var_dump($model->personid);

something


 array

0 => 

array

  'id' => string '24' (length=2)

error is


  personid must be a number.

the thing is session stores it as string but i need it as integer as personid is integer …

as well i want to know have we to configure session in config/main … do i need a db for it

Please help i am losing my mind on this

this is how you do it




public function fetch($username,$password)

{


    $sql="select id FROM user where ( username='".$username. "' AND password='".$password."')";

    $connection=Yii::app()->db;

    $command=$connection->createCommand($sql);

    // use queryColumn if you have to fetch only a single column

    $resuserid=$command->queryColumn();

    //var_dump($resuserid);

    $result=array();

    foreach($resuserid as $val)

    {

         // you can cast each value as integer like this

        $result=(int) $val;


    }

    return $result;

    }