php SQL之where语句生成器

yipeiwu_com6年前PHP代码库
复制代码 代码如下:

//生成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长连接实现与使用方法。分享给大家供大家参考,具体如下: 长连接技术(Long Polling) 在服务器端hold住一个连接, 不立即返回, 直到有数据才返回, 这就...

说明的比较细的php 正则学习实例

"^The": 匹配以 "The"开头的字符串;    "of despair$": 匹配以 "of despair...

phpmailer绑定邮箱的实现方法

phpmailer绑定邮箱的实现方法

本文实例讲述了phpmailer绑定邮箱的实现方法。分享给大家供大家参考,具体如下: 效果如下: 1.配置 <?php return array ( 'email...

PHP开发中四种查询返回结果分析

1.<!--使用mysql_result()来获取数据--> 复制代码 代码如下: <?php $connection=mysql_connect("localhost...

一个简单的php路由类

本文实例为大家分享了php编写一个简单的路由类,供大家参考,具体内容如下 <?php namespace cmhc\Hcrail; class Hcrail {...