php SQL之where语句生成器
更新时间:2009年03月24日 01:08:07 作者:
每次都写SQL条件语句,很麻烦,容易出错,写了个函数整合到数据库类里,用来根据传入的数组,自动生成 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;
}
相关文章
学习php设计模式 php实现原型模式(prototype)
这篇文章主要介绍了php设计模式中的原型模式,使用php实现原型模式,感兴趣的小伙伴们可以参考一下2015-12-12
PHP+Ajax实现无刷新分页实例详解(附demo源码下载)
这篇文章主要介绍了PHP+Ajax实现无刷新分页的方法,以完整实例形式详细分析了PHP结合ajax实现无刷新分页的具体步骤与相关技巧,并附带demo源码供读者下载参考,需要的朋友可以参考下2016-04-04
浅析Dos下运行php.exe,出现没有找到php_mbstring.dll 错误的解决方法
本篇文章是对在Dos下运行php.exe,出现没有找到php_mbstring.dll 错误的解决方法进行了详细的分析介绍,需要的朋友参考下2013-06-06


最新评论