Given a search string I need to select every record where (in the field the search is performed on) there is at least one word that begins with the given text.
For example:
'John Doe'
Have to be be selected with search strings like:
'joh'
'do'
'JOHN doe'
Have not to be selected with
'ohn'
'oe'
I need (possibly) to avoid full text search.
What I've found to work is
$query = 'SELECT * FROM MYTABLE WHERE SEARCHFIELD LIKE "' . $searchText . '%"'
. 'OR SEARCHFIELD LIKE "% ' . $searchText . '%"'
I'm asking if there is a better way to do that.
(for "better way" I mean better performance or same performance but more elegant)
Also, as the query will be built up with a prepared statement, how should I unescape LIKE metacharacters in the search string?