Home > database >  A fuzzy query problem troubled for a long time
A fuzzy query problem troubled for a long time

Time:09-28

Such as search SA - PJ1234 - # - 12 h1301, like fuzzy query the database in PHP, found that can't always check, found that while reading the search string search string into SA - PJ1234 - and why the content of the truncated after #?
The front desk input: & lt; Input the name="code" type='text' placeholder="please enter the number" & gt;
Read data: $code=trim ($_GET [] "code");
Query data: $SQL="select * from tgs_code where code like '% % $code limit 1";

CodePudding user response:

Just found and tested the # & amp; | the three symbol will appear this problem, such as other! % @ $... * () & lt;>/? Among works, if it is + will empty one, don't know is what circumstance,

CodePudding user response:

When you construct the query need to special characters, such as # & amp; | \ such as character processing, inside you read characters find these special characters, and then in front of these special characters \ can increase escape symbol

CodePudding user response:

Or change to another kind of efficient method:

Read data: $code=trim ($_GET [] "code");
Query data: $SQL="select * from tgs_code where locate (' $code, code) & gt; 0 limit 1 ";

CodePudding user response:

# # are comments symbols in mysql, after things are as the content of the comments, will not do resolution, # and | should also have the corresponding effect, but the is not very clear, have know a great god can science,

CodePudding user response:

'& amp; 'and' | 'is an operator, feeling should be able to have an impact on the query, should not be truncation,

CodePudding user response:


Use quotation marks should be no problem,

CodePudding user response:

$SQL="select * from tgs_code where code like '% {$code} %' limit 1";
Try this?

CodePudding user response:

refer to the second floor surl61240 response:
when you construct the query need to special characters, such as # & amp; | \ such as character processing, inside you read characters find these special characters, and then increase escape symbol in front of these special characters \ can


A point

CodePudding user response:

The SQL # are comments symbol, add a backslash \ escape a try
  • Related