dqwh1205 2016-04-25 19:36
浏览 651
已采纳

如何在yii2中使用WHERE - LIKE子句并使用区分大小写进行LIKE模式搜索? [重复]

This question already has an answer here:

$aa = India::find();
$players = $aa
            ->where('player LIKE :query', [':query'=>'S%'])
            ->orderBy('position, player')->all();
$countnumber = $aa->count();

This code returns results without case sensitivity. Gives results where Player name starts with 'S' or 's'.

But I want to make, just to select Player names only with 'S'. How to restrict it to select with case sensitivity in PHP Yii2 Framworok ?

</div>
  • 写回答

1条回答 默认 最新

  • drr47973 2016-04-26 00:55
    关注

    In case you are using MySQL you can make your query with BINARY

    So your Yii2 code should be something like this:

    $players = India::find()
                ->where(['LIKE BINARY', 'player', $query_parameter])
                ->orderBy('position, player')->all();
    
    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?