亲宝软件园·资讯

展开

where语句生成器 php SQL之where语句生成器

人气:2
想了解php SQL之where语句生成器的相关内容吗,在本文为您仔细讲解where语句生成器的相关知识和一些Code实例,欢迎阅读和指正,我们先划重点:SQL,where,语句生成器,下面大家一起来学习吧。
复制代码 代码如下:

//生成where字符串
function get_where($arg = null) {
foreach ((array)$arg as $key => $val) {
if(is_int($key)) {
$where .= " $val ";
}else {
if(is_string($val)) {
if($val === null) {
$where .= " and $key is null ";
}else {
$where .= " and $key = '$val' ";
}
}elseif(is_array($val)) {
foreach ($val as $v) {
if(is_string($v)) {
$in .= $in ? ",'$v'" : "'$v'";
}else {
$in .= $in ? ",$v" : "$v";
}
}
$where .= " and $key in ($in)";
}else {
$where .= " and $key = $val ";
}
}
}
return $where;
}

加载全部内容

相关教程
猜你喜欢
用户评论