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

时间:2023-03-10 07:20:31
写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语句连接的时候注意的一个小细节

根据图中的输出就能知道出错的原因了了,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);