Home  >  Article  >  Backend Development  >  php中关于sql拼接时标点符号出现的问题

php中关于sql拼接时标点符号出现的问题

WBOY
WBOYOriginal
2016-06-23 13:57:251216browse

初学php,遇到了个奇怪的问题,让大侠们见笑了,拼接语句如下:

 $sql = 'select cat_id,cat_name,parent_id from ' . $this->table . ' where parent_id=' . $id;//能通过,正解  $sql = 'select cat_id,cat_name,parent_id from' . $this->table . 'where parent_id=' . $id;


为啥符号的空位不同,拼接的结果会有差异, 不解中,求解答?


回复讨论(解决方案)

你把两句输出之后对比下就知道了。
第一句....  from table where...
第一句....  fromtablewhere...

第二句中from 、table和where连在一起了,还能正确吗?

select cat_id,cat_name,parent_id fromcategorywhere parent_id=42delete from category where cat_id=42

跑的太快了,基础没打好,谢谢版主提醒!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn