How to search a MySQL database for a specific row

I am trying to set up a search function on my site that will only return exact matches to the keyword entered by the user. Therefore, if a user searches for a “dog,” I don’t want an article called “Doggy Style” to appear in the search results (just an example, I really don't have an article with that name). This, of course, does just that:

SELECT * FROM articles WHERE article_title LIKE '%$searchQuery%'

$ searchQuery is a PHP variable taken from a user input form. So can only exact matches be returned?

+3
source share
3 answers
SELECT * FROM articles WHERE article_title = '$searchQuery'

. "like" "=" , % .

MySQL, .

+4

:

SELECT * FROM articles WHERE article_title = '$searchQuery'

MySql .

+1
SELECT * FROM articles WHERE article_title = '$searchQuery'
+1
source

Source: https://habr.com/ru/post/1737873/


All Articles