views:

50

answers:

2

I want to run a query like this:

SELECT * FROM table WHERE field LIKE '%search_term%'

In CI you can bind parameters to queries, if you used field=? but this does not work for field LIKE "%?%". From debugging output it seems the query used is field LIKE "%'search'%".

Is there an alternative way to do searching in CodeIgniter?

+1  A: 

You can use this query:

SELECT * FROM table WHERE field LIKE ?

And bind with %search% instead of search.

You should be aware that this query will be slow in MySQL. You might want to look at free-text search instead (Lucene, Sphinx, or MySQL's built-in free-text search functions).

Mark Byers
Thanks, that worked. This isn't for a major part of my script so the speed isn't an issue.
DisgruntledGoat
A: 

what i can understand CI is adding quotes, pass FALSE as third parameter while binding to prevent CI adding quotes.

Sandy