时间:2021-07-01 10:21:17 帮助过:20人阅读
$field_func="COUNT|AVG|FIRST|LAST|MAX|MIN|SUM|TOP";
$where_field="Where|or|xor|and|in";
$param="name";
$sql_param_list=array();
if(false!==strpos($param,",")){//判断是否存在“,”
$sql_param_list["field"] = $param;
}else{
if(preg_match("/\b(".strtolower($field_func).")\b\((\*|[a-zA-Z_`])+\)/i", $param)){
$sql_param_list["field"] =$param;
}elseif(preg_match("/\b(".$where_field.")\b/i", $param)||preg_match("/(>|>|=)/i", $param)){//判断where
$sql_param_list["where"] =$param;
}elseif(preg_match("/\b(order|limit|group|)\b/i", $param,$param_name)){//判断order|limit|group
switch ($param_name[0]){
case "order" : $sql_param_list["order"] =$param;
break;
case "limit" : $sql_param_list["limit"] =$param;
break;
case "group" : $sql_param_list["group"] =$param;
break;
}
}else{
$sql_param_list["field"] =$param;
}
}
print_r($sql_param_list);
}elseif(preg_match("/\b(order
------解决方案--------------------
limit
------解决方案--------------------
group
------解决方案--------------------
)\b/i", $param,$param_name)){//判断order
------解决方案--------------------
limit
------解决方案--------------------
group
==> "/\b(order
------解决方案--------------------
limit
------解决方案--------------------
group)\b/i", //正则多了个或