Receiving NULL as value when I called this SQL statement (the record exists in the MySQL DB). How can use the LIKE function in Yii2? Thanks.
$command = $connection->createCommand("SELECT user_id
WHERE name LIKE '%:_username%'");
$this->id_user = $command->queryScalar();
In Yii2 you can use also a activeQuery Notation this way
$query = new Query; $query->select('userid') ->from('user') ->where(['like', 'user', $this->username ); $command = $query->createCommand(); $this->id_user = $command->queryScalar();