Maison  >  Article  >  développement back-end  >  php中关于sql拼接时标点符号出现的问题

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

WBOY
WBOYoriginal
2016-06-23 13:57:251217parcourir

初学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

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

Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn