如何使用mysqli正则表达式匹配哈希标记

since i could not understand much of the answers given to my previous question (Here),i was forced to do an extensive google search on mysqli and hashtags and i appear to have found a solution as the below code

THE CODE

$count_hash = mysqli_query($db,"SELECT * FROM tablename WHERE colummname  REGEXP '[[:<:]][[:>:]]'")or trigger_error(mysqli_error());

my question

suppose i have the following structure

id|text          |
1 | search engine|
2 | search       |

and suppose the user enters the query #search the query is supposed to find the posts that have the text #search in it and count them then show the count

the problem : i dont know how do i use it meaning ive got errors with everything ive tried

what ive tried

....REGEXP '[[:<:]].$query.[[:>:]]'.....

firstly remove the # from the query like so:

$query=str_replace('#','',$query); 

then query the db:

select count(id) as TOTAL from foo where term LIKE '%$query%'

Demo:http://sqlfiddle.com/#!2/f3c2b/1/0

plan B, do it all in mysql:

select count(id) as TOTAL from foo
where term LIKE REPLACE("%#$query%","#","")

DEmo: http://sqlfiddle.com/#!2/650137/1/0