当我在DQL中使用2 where语句时,无法获得结果集

时间:2011-02-10 15:43:55

标签: doctrine

I.m使用ORM Doctrine 1.2,我收到此错误消息:

未捕获的异常'Doctrine_Connection_Mysql_Exception',消息'SQLSTATE [HY093]:参数号无效:混合名称和位置参数'

编写DQL的方法:

public function SearchComboBothDates($searchOptionType,$searchValue,$dateFrom,$dateTill)
{
     $result =  $this->createQuery()
                    ->from("Orders o")
                    ->innerJoin("o.Contractants c")
                    ->innerJoin("c.Persons p")
                    ->innerJoin("p.Addresses a")
                    ->innerJoin("o.Resellers r")
                    ->innerJoin("r.Companies cp")
                    ->innerJoin("o.Cars ca")
                    ->innerJoin("ca.CarTypeScopes cts")
                    ->innerJoin("cts.CarTypes ct")
                    ->innerJoin("ct.CarBrands cb")
                    ->innerJoin("o.Users u")
                    ->innerJoin("o.OrderTypes ot")                      
                    ->where("o.".$searchOptionType." LIKE :searchvalue", array(':searchvalue' => "%".$searchValue."%"))
                    ->andWhere("o.order_date BETWEEN ? AND ? ", array($dateFrom, $dateTill))
                    ->execute();    
    return $result;
}

我确定'$ searchOptionType,$ searchValue,$ dateFrom,$ dateTill'设置正确。

请给我一些合作的东西,这样可以解决这个问题。

费尔。

1 个答案:

答案 0 :(得分:1)

试试这个;它应该避免混合两种参数类型:

public function SearchComboBothDates($searchOptionType,$searchValue,$dateFrom,$dateTill)
{
     $result =  $this->createQuery()
                    ->from("Orders o")
                    ->innerJoin("o.Contractants c")
                    ->innerJoin("c.Persons p")
                    ->innerJoin("p.Addresses a")
                    ->innerJoin("o.Resellers r")
                    ->innerJoin("r.Companies cp")
                    ->innerJoin("o.Cars ca")
                    ->innerJoin("ca.CarTypeScopes cts")
                    ->innerJoin("cts.CarTypes ct")
                    ->innerJoin("ct.CarBrands cb")
                    ->innerJoin("o.Users u")
                    ->innerJoin("o.OrderTypes ot")                      
                    ->where("o.".$searchOptionType." LIKE ?", "%".$searchValue."%")
                    ->andWhere("o.order_date BETWEEN ? AND ? ", array($dateFrom, $dateTill))
                    ->execute();    
    return $result;
}