Yii Convert Integer To String

I wonder why yii convert integer to string ?

$data =Yii::$app->db->createCommand(‘SELECT id FROM foo’);



here is the result of var_dump()

array (size=1)

‘id’ => string ‘5’ (length=1)


I want the result data type as integer. Any solution ?

You are dumping "createCommand" results, that is a yii\db\Command instance.

I think you wanted to apply "queryScalar()" to Command instance:

$data =Yii::$app->db->createCommand('SELECT id FROM foo')->queryScalar();