写sql语句连接的时候注意的一个小细节

我在写权限的查询的时候,用到了sql语句的链接写一下出错的时候的代码

 $sqlpid="select auth_name from sw_auth where auth_level=0";
     if(session('mg_id')!=5){
         $sqlpid.="and auth_id in ($ids)";
     }
     show($sqlpid);

出错的截图

根据图中的输出就能知道出错的原因了了,sql语句没写对

正确的代码

 $sqlpid="select auth_name from sw_auth where auth_level=0";
     if(session('mg_id')!=5){
         $sqlpid.=" and auth_id in ($ids)";
     }
     show($sqlpid);

 

posted @ 2015-07-10 20:16  杰杰顺利  阅读(247)  评论(0编辑  收藏  举报