网络编程 
首页 > 网络编程 > 浏览文章

php SQL之where语句生成器

(编辑:jimmy 日期: 2024/9/25 浏览:3 次 )
复制代码 代码如下:
//生成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;
}
上一篇:PHP获取类中常量,属性,及方法列表的方法
下一篇:php cookie 作用范围–不要在当前页面使用你的cookie
友情链接:杰晶网络 DDR爱好者之家 南强小屋 黑松山资源网 白云城资源网 SiteMap