Answer the question
In order to leave comments, you need to log in
How to make MySQL treat underscore as text?
How to make SQL treat underscores as text (and any other characters in general).
For example, I want to find data in a column strictly equal to Alexey, he calmly finds and issues, but if I enter Alex_ey, he will not find anything, because SQL replaces "_" with any character, which is very annoying.
LIKE %% doesn't match because it looks for all matches, but I need a strict one.
I use the RedBeanPHP library, code example below.
$searchlogin = R::getAll('select * from teleg where nik = :login',
array(':login'=>$lgtg)
);
Answer the question
In order to leave comments, you need to log in
Remove underlining.
Or LIKE ESCAPE
s_t_u_v_w and click find, I should display all strict matches with this nickname
SELECT * FROM teleg WHERE nik = 's_t_u_v_w'
SELECT * FROM teleg WHERE nik LIKE 's!_t!_u!_v!_w' ESCAPE '!'
At the moment, due to the fact that the _ symbol is replaced, I can not find nicknames with his participation.SQL Server does not replace anything.
put enters in the cells, because of this nothing was found
SELECT * FROM teleg WHERE nik = 's_t_u_v_w' + CHAR(13)
SELECT * FROM teleg WHERE REPLACE(nik, CHAR(13), '') = 's_t_u_v_w'
Not all cells have some kind of character (or whatever it is).
SELECT CONVERT(VARCHAR, CAST(nik AS binary), 2) FROM teleg
CHAR(13)
or CHAR(0x0D)
and remove itUPDATE teleg SET nik = REPLACE(nik, CHAR(0x0D), '')
TRIM
fails because space CHAR(0x20)
is not the last character. SELECT HEX(nik) FROM teleg
UPDATE teleg SET nik = REPLACE(nik, CAST( 0x0D AS CHAR ), '')
And does religion not allow the old "children's" method of shielding to be applied?
$str_like = str_replace(['_', '%'], ['\_', '\%'], 'Alex_ey');
$sql = "SELECT * FROM `table` WHERE `field` LIKE '".$str_like."'";
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question