sql - How to write query with like in Doctrine2 -
i want write statement doctrine's query builder:
where e.date '%$month'
(i want selected date end value of variable $month)
e.date of type date , has values this: '05/05/2013'
$month variable string value this: '05/2013'
so want take items month 05/2013 query
here whole function:
public function findformonthandcat($user, $month, $category) { $q = $this ->createquerybuilder('e') ->where('e.date :month') //i don't know how write line ->andwhere('e.user = :user') ->andwhere('e.category = :category') ->setparameter('date', $month) ->setparameter('user', $user) ->setparameter('category', $category) ->getquery(); return $q->getresult(); }
i tried this:
->where($q->expr()->like('e.category', '%:month')
but says i'm calling expr() on non-object.
i tried this:
public function findexpensesformonthandcat($user, $month, $category) { $q = $this ->createquerybuilder('e') ->where('e.date :month') ->andwhere('e.user = :user') ->andwhere('e.category = :category') ->setparameter('date', '%'.$month) ->setparameter('user', $user) ->setparameter('category', $category) ->getquery(); return $q->getresult(); }
but says invalid parameter: token date not defined in query.
can me please? lot in advance!
replace date 'month', that's name of parameter :
public function findformonthandcat($user, $month, $category) { $q = $this ->createquerybuilder('e') ->where('e.date :month') ->andwhere('e.user = :user') ->andwhere('e.category = :category') ->setparameter('month', "%$month") ->setparameter('user', $user) ->setparameter('category', $category) ->getquery(); return $q->getresult(); }
Comments
Post a Comment