Different results between query and queryAll

Hi all,

I do this:


        

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

        $sql = "select * from tbl_google  where tbl_google.page = '$page'";

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


        $dataReader = $command->query();

        return $dataReader;

When I ask




$dataReader->count(); // return 1

$dataReader->current(); // Empty

When I do


        $sql = "select * from tbl_google  where tbl_google.page = '$page'";

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


        $dataReader = $command->queryAll();

        return $dataReader;

Then $dataReader[0][‘columnName’] is not empty and gives me the good result

Do you know why the first method is not good ?

Thanks

Instead of $dataReader->current() try with read() - http://www.yiiframework.com/doc/api/1.1/CDbDataReader#read-detail

mdomba,

It works very well.

But I wonder why $dataReader->current();

Is it a misunderstanding I did from reading API or is it a bug ?

Nevertheless thanks you very much

I’m not sure… but as I see this…

read() gives you the first row and advances to the next… so by calling read() second time you would get the second row…

instead calling current() after read() it should return the same first row…