我有一个表,其中逗号分隔另一个表的 id 我想在 cakephp 中以正确的形式使用 find 函数使用以下查询
"select * from special_offers where find_in_set('".$storeId."', stores) and user_id = '". $userId ."'";
像这样使用
$data = $this->SpecialOffer->find('all',array('conditions' => array('SpecialOffer.user_id' => $userId ,'FIND_IN_SET(\''. $storeId .'\',SpecialOffer.stores1)')));
希望这可以帮助你
为了避免SQL注入,也可以这样绑定参数:
$data = $this->SpecialOffer->find('all')
->where([
'SpecialOffer.user_id' => $userId,
'FIND_IN_SET(:storeId, SpecialOffer.stores1)',
])
->bind(':storeId', $storeId, 'integer');