Jan Beeck Jan Beeck - 9 months ago 219
PHP Question

How to call the SQL LIKE function in Yii2?

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;
      ->where(['like', 'user', $this->username );

  $command = $query->createCommand();

  $this->id_user = $command->queryScalar();