I'm trying to search in my database with LIKE
now builder is working great except 1 thing:
I would like to have a %
in front and back of every parameter, but the way the builder works, it places a '
in front and back of every param when it is executed. so I can't add them manually
Is there a way to do this?
this is the query:
$queryBuilder = $this->db->createQueryBuilder();
$queryBuilder
->select('t.id', 't.status', 't.title', 't.price', 'u.username')
->from('tools', 't')
->innerJoin('t', 'key_for_tools', 'kft', 'kft.tools_id = t.id')
->innerJoin('t', 'keywords', 'k', 'kft.key_id = k.id')
->innerJoin('t', 'users', 'u', 't.user_id = u.id');
for($i=0; $i < sizeof($tags); $i++){
$queryBuilder->andWhere('k.key LIKE %' . $queryBuilder->createPositionalParameter($tags[$i]) . '%');
}
$result = $this->db->fetchAll($queryBuilder->getSql(),$tags);
but this generates a string like:
SELECT t.id, t.status, t.title, t.price, u.username FROM tools t INNER JOIN key_for_tools kft ON kft.tools_id = t.id INNER JOIN keywords k ON kft.key_id = k.id INNER JOIN users u ON t.user_id = u.id WHERE (k.key LIKE %'tag'%)
but I want the %
between the '
if anyone knows how to do this