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 常用数组内部函数(Array Functions)介绍

本章讲述几个常用的 PHP 数组内部函数。 在前面我们已经介绍过PHP 数组,创建一个数组用 array() 函数,删除一个数组元素用 unset() 函数。本章节我们还要学习一些其它常...

PHP 处理图片的类实现代码

复制代码 代码如下: <?php /** * author:yagas * email:yagas60@21cn.com */ class Image { /** 类保护变量 */...

PHP 分页类(模仿google)-面试题目解答

笔试回答的不太好,特别是JS部分,也是许久都没复习的原因。 上机题目是要写一个仿google分页的类,当要取类似9/2的最大整数,却怎么也想不起函数ceil的名字,晕了半天。 最后测试程...

使用dump函数,给php加断点测试

复制代码 代码如下:function dump($var, $echo=true,$label=null, $strict=true){    $label...

分享PHP计算两个日期相差天数的代码

本文实例讲述了php计算两个日期相差天数的方法。分享给大家供大家参考。具体实现方法如下: <?php $date1 = date( 'Y-m-d' ); $date2...