Maison  >  Article  >  développement back-end  >  php SQL之where语句生成器_PHP教程

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

WBOY
WBOYoriginal
2016-07-21 15:46:56930parcourir

复制代码 代码如下:

//生成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...
Déclaration:
Le contenu de cet article est volontairement contribué par les internautes et les droits d'auteur appartiennent à l'auteur original. Ce site n'assume aucune responsabilité légale correspondante. Si vous trouvez un contenu suspecté de plagiat ou de contrefaçon, veuillez contacter admin@php.cn