php SQL之where语句生成器

yipeiwu_com5年前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中动态变量用法。分享给大家供大家参考。具体分析如下: 定义的固定变量: $my_pic_1=$row["pic_1"]; $my_pic_2=$row["pic_...

php简单创建zip压缩文件的方法

本文实例讲述了php简单创建zip压缩文件的方法。分享给大家供大家参考,具体如下: /* creates a compressed zip file */ function crea...

php设计模式之单例模式代码

php设计模式之单例模式的例子,供大家参考,具体内容如下 <?php /** * php设计模式 单例模式 */ class Fruit{...

php获取$_POST同名参数数组的实现介绍

今天写php的时候发现$_POST["arr"]无法获取参数arr的数组,记录一下。例如有以下表单需要提交:复制代码 代码如下:  <input type="checkbox" n...

php 获取一个月第一天与最后一天的代码

复制代码 代码如下:function getthemonth($date) { $firstday = date('Y-m-01', strtotime($date)); $lastda...