How to use an user variables in MySQL LIKE clause?
Solution 1:
SET @email = '[email protected]';
SELECT email from `user` WHERE email LIKE CONCAT('%', @email, '%');
Solution 2:
Works without concat():
LIKE '%{$var}%'
(Mysql version 5.+)
Solution 3:
You may have error
Error Code: 1267. Illegal mix of collations for operation 'like' 0.016 sec
In this case you need to specify the same collation as used for your table like that:
SET @email = '[email protected]' COLLATE utf8_unicode_ci;