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 工程的办法

这篇文章介绍在 PHP 的面向对象编程(OOP)。我将演示如何用面向对象的概念编出较少的代码但更好的程序。祝大家好运。     面向对象编程的概念...

PHP file_get_contents设置超时处理方法

file_get_contents的超时处理 话说,从PHP5开始,file_get_content已经支持context了(手册上写着:5.0.0 Added the context...

php中几种常见安全设置详解

另外,目前闹的轰轰烈烈的SQL Injection也是在PHP上有很多利用方式,所以要保证安全,PHP代码编写是一方面,PHP的配置更是非常关键。 我们php手手工安装的,php的默认...

解析用PHP读写音频文件信息的详解(支持WMA和MP3)

复制代码 代码如下:<?php// AudioExif.class.php// 用PHP进行音频文件头部信息的读取与写入// 目前只支持 WMA 和 MP3 两种格式, 只支持常用...

php提取字符串中网站url地址的方法

本文实例讲述了php提取字符串中网站url地址的方法。分享给大家供大家参考。具体分析如下: 今天写一个问答系统上线之后发现有很多人发链接了,由于业务部门要我们过滤掉网站地址了,下面我给大...