Fela
Fela

Reputation: 11

MySQL: escape space from query

Is there a way using MySQL, to query a value containing a space, but as some sort of escape character? It's for an instant search engine I'm building (I'm trying to incorporate special search strings such as quotes to search for exact string).

cheers

Upvotes: 1

Views: 3824

Answers (2)

Jonathan Kuhn
Jonathan Kuhn

Reputation: 15311

Full-text indexes are what you should use. They handle all sorts of key words/characters (such as quoting a string to get exact match, -someword for saying someword can't be in the result and +someword for saying someword has to be in the result) without having to do anything special in your code (other than changing your query a little). The database will do the search for you and return the most relevant results at the top of the query. It is really quite easy to get going too.

Mysql Manual

Using full-text searching (implementation help)

Upvotes: 1

m1tk4
m1tk4

Reputation: 3477

select * from sometable where somefield like '%oh no%';

Upvotes: 1

Related Questions