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实现的CSS更新类实例

本文实例讲述了php实现的CSS更新类及其用法,非常实用。分享给大家供大家参考。具体如下: CSSUpdate.class.php类文件如下: <?php /** c...

php简单实现发送带附件的邮件

本文实例讲述了php简单实现发送带附件的邮件。分享给大家供大家参考。具体如下: 下面是静态html代码: <html> <head> <title&...

php 备份数据库代码(生成word,excel,json,xml,sql)

单表备份代码:复制代码 代码如下:<?php    class Db    {    &n...

基于php中使用excel的简单介绍

基于php中使用excel的简单介绍

在工作中需要处理多语言的翻译问题,翻译都是写在excel表格里面。为了处理方便我就保留中文和英文两列。 这样需要将这些数据从excel中取出来,然乎保存在excel的数组中,通过使用循环...

PHP中通过语义URL防止网站被攻击的方法分享

什么是语义URL 攻击? 好奇心是很多攻击者的主要动机,语义URL 攻击就是一个很好的例子。此类攻击主要包括对URL 进行编辑以期发现一些有趣的事情。 例如,如果用户chris 点击了你...