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 file_get_contents 函数超时的几种解决方法

这里就简单介绍两种: 一、增加超时的时间限制 这里需要注意:set_time_limit只是设置你的PHP程序的超时时间,而不是file_get_contents函数读取URL的超时时间...

PHP中file_exists与is_file,is_dir的区别介绍

很显然file_exists是受了asp的影响,因为asp不但有fileExists还有folderExists,driverExists,那么PHP中file_exists是什么意思呢...

PHP使用curl模拟post上传及接收文件的方法

本文实例讲述了PHP使用curl模拟post上传及接收文件的方法。分享给大家供大家参考,具体如下: public function Action_Upload(){ $th...

PHP 实现 驼峰命名与下划线命名互转 的函数功能

驼峰命名和下划线命名经常需要互转, 尤其是在与前端通过json格式数据交互时,相当方便。下面介绍php的实现方式.PHP驼峰命名转下划线命名    /...

php自动给网址加上链接的方法

本文实例讲述了php自动给网址加上链接的方法。分享给大家供大家参考。具体实现方法如下: 这里自动匹配页面里的网址,包含http,ftp等,自动给网址加上链接 function tex...