如何在cakephp find方法中使用find_in_set

gv8xihay  于 9个月前  发布在  PHP
关注(0)|答案(2)|浏览(217)

我有一个表,其中逗号分隔另一个表的ID,我想使用以下查询在cakephp在适当的形式与查找功能

"select * from special_offers where find_in_set('".$storeId."', stores) and user_id = '". $userId ."'";

字符串

tag5nh1u

tag5nh1u1#

像这样使用

$data = $this->SpecialOffer->find('all',array('conditions' => array('SpecialOffer.user_id' => $userId ,'FIND_IN_SET(\''. $storeId .'\',SpecialOffer.stores1)')));

字符串
希望这可以帮助你

7dl7o3gd

7dl7o3gd2#

为了避免SQL注入,也可以像这样绑定参数:

$data = $this->SpecialOffer->find('all')
    ->where([
        'SpecialOffer.user_id' => $userId,
        'FIND_IN_SET(:storeId, SpecialOffer.stores1)',
    ])
    ->bind(':storeId', $storeId, 'integer');

字符串

相关问题