views:

107

answers:

2

I am making a Doctrine query and I have to do a wildcard match in the where clause. How should I escape the variable that I want to insert?

The query I want to get:

SELECT u.* FROM User as u WHERE name LIKE %var%

The php code until now:

   $query = Doctrine_Query::create()
                ->from('User u')
                ->where();

What should come in the where clause? The variable I want to match is $name

+1  A: 

Something bad happened to Doctrine's documentation so here's the Google copy (check Like Expressions section)

...
->where('u.name LIKE ?', array("%$name%"));
Crozin
+2  A: 

Works for me with:

->where('u.username LIKE ?', '%'.$username.'%')
Tom