如何在Yii2活动记录中使用内置的MySQL函数? 这是我要隐藏在活动记录中的查询。
以及如何在SearchModel
中实现相同功能?
SELECT * FROM `dts_track` where concat(date_received,time_received) != concat(date_released,time_released)
答案 0 :(得分:2)
您可以将字符串格式用于
public function search($params)
{
$query = YourModel::find();
$dataProvider = new ActiveDataProvider([
'query' => $query,
]);
if (!($this->load($params) && $this->validate())) {
return $dataProvider;
}
$query->andWhere('concat(date_received,time_received) != concat(date_released,time_released)');
return $dataProvider;
}
答案 1 :(得分:-2)
在搜索功能中,让我为更好的生活做出贡献:
if(isset($params['date_received']) AND isset($params['time_received'])){
$datereceived = $params['date_received'].$params['time_received'];
}
if(isset($params['date_released']) AND isset($params['time_released'])){
$datereleased = $params['date_released'].$params['time_released'];
}
$query->andWhere(':date1 != :date2', [':date1' => $datereceived , ':date2' => $datereleased ]);