我有一个表格,我想在我的数据库中搜索。我用所有参数创建对象,但我有一个问题。当在一个文本字段中写入时,搜索工作正常并且查询运行正确。当编写两个或多个文本字段参数不起作用并且我执行查询失败时:
WHERE ((((id_reservation=:id_reservation) AND (start=:start)) AND (end=:end)) AND (fkCustomer.first_name=:first_name))
参数不会替换。
$criteria=new CDbCriteria;
$criteria->with =array('fkCustomer');
if(!empty($start))
{
$criteria->addCondition('start=:start');
$criteria->params=array(':start'=>$start);
}
if(!empty($end))
{
$criteria->addCondition('end=:end');
$criteria->params=array(':end'=>$end);
}
if(!empty($merge->customer_name))
{
$criteria->addCondition('fkCustomer.first_name=:first_name');
$criteria->params=array(':first_name'=>$merge->customer_name);
}
if(!empty($merge->customer_surname))
{
$criteria->addCondition('fkCustomer.last_name=:last_name');
$criteria->params=array(':last_name'=>$merge->customer_surname);
}
if(!empty($merge->customer_email))
{
$criteria->addCondition('fkCustomer.email=:email');
$criteria->params=array(':email'=>$merge->customer_email);
}
$criteria->limit = 100;