2

Maybe a noob question but I have to ask...

This is the query I need:

select title from internships where title like '% someParameter %'

I have to use this in my Repository in my Silex project, so I wrote a function in my repo:

public function getTitleQuery($title) {
    return $this->db->fetchAll('select title from internships where title like \'% ? %\' ', array($title));
}

When I escape the single quotes like \' php sees the question mark as a question mark and not as a parameter.

4

1 回答 1

4

在 sql 中试试这个:

'select title from internships where title like ?'

并在数组部分放

array("%{$title}%")

如何使用 LIKE 语句创建 PDO 参数化查询?

于 2013-05-18T00:10:49.933 回答