欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  后端开发

php SQL之where语句生成器_PHP教程

程序员文章站 2024-02-14 18:44:58
...
复制代码 代码如下:

//生成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;
}

www.bkjia.comtruehttp://www.bkjia.com/PHPjc/320031.htmlTechArticle复制代码 代码如下: //生成where字符串 function get_where($arg = null) { foreach ((array)$arg as $key = $val) { if(is_int($key)) { $where .= " $val "; }else { if(is_stri...