SQL:为什么这个查询不会被破坏

时间:2021-07-23 00:11:15

I am learning SQL .

我正在学习SQL。

The developer has enclosed the $id in double quotes. So when I put id=1" the query breaks.

开发人员将$ id括在双引号中。所以当我把id = 1时,查询就会中断。

ERROR : "1"") LIMIT 0,1 at line 1

However when I put id=1' (single quotes) the query doesn't not break.
How is this possible? Single quotes does not have a pair and it should break.

但是,当我输入id = 1'(单引号)时,查询不会中断。这怎么可能?单引号没有一对,它应该破坏。

1 个解决方案

#1


0  

in your sql

在你的SQL中

do your variables enclosed by single quotes

用单引号括起你的变量

  '$id'

or no quotes

或没有报价

   $id

or like that if your query is with double quotes $query = "select ...." ;

或者像你的查询是双引号$ query =“select ....”;

  '".$id."'

or like that if your query is with single quotes $query = 'select ....' ;

或者如果您的查询是单引号$ query ='select ....';

then your variable should be

那你的变量应该是

  $id

#1


0  

in your sql

在你的SQL中

do your variables enclosed by single quotes

用单引号括起你的变量

  '$id'

or no quotes

或没有报价

   $id

or like that if your query is with double quotes $query = "select ...." ;

或者像你的查询是双引号$ query =“select ....”;

  '".$id."'

or like that if your query is with single quotes $query = 'select ....' ;

或者如果您的查询是单引号$ query ='select ....';

then your variable should be

那你的变量应该是

  $id