php SQL where statement generator_PHP tutorial

WBOY
Release: 2016-07-21 15:46:56
Original
979 people have browsed it

Copy code The code is as follows:

//Generate where string
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.htmlTechArticleCopy code The code is as follows: //Generate where string function get_where($arg = null) { foreach ((array )$arg as $key = $val) { if(is_int($key)) { $where .= " $val "; }else { if(is_stri...
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template