As a parameter in LIKE '%' in the prepared expression



  • I. yii 2♪ Such request

    $films = Yii::$app->db->createCommand("SELECT descr, poster FROM {{films}} WHERE [[name_orig]] LIKE '%:filmname%'")
               ->bindParam(':filmname', $name, PDO::PARAM_STR)
               ->queryAll();
    

    He's not working. Problem at the station LIKE '%:filmname%'

    Everything works if the request is simplified and written:

    $films = Yii::$app->db->createCommand("SELECT descr, poster FROM {{films}} WHERE [[name_orig]] LIKE :filmname")
               ->bindParam(':filmname', $name, PDO::PARAM_STR)
               ->queryAll();
    

    Tell me how to rewrite the request to work. LIKE '%:filmname%'



  • Try that. '%'.$name.'%'

    $films = Yii::$app->db
        ->createCommand("SELECT descr, poster FROM {{films}} WHERE [[name_orig]] LIKE :filmname")
        ->bindParam(':filmname', '%'.$name.'%', PDO::PARAM_STR)
        ->queryAll();
    



Suggested Topics

  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2
  • 2