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;
}

相关文章

慎用preg_replace危险的/e修饰符(一句话后门常用)

preg_replace函数原型: mixed preg_replace ( mixed pattern, mixed replacement, mixed subject [, int...

php 伪造本地文件包含漏洞的代码

代码: 复制代码 代码如下: <?php $page=$_GET['page']; include($page.'php'); ?> 你可以这样使用 http://www....

PHP对象链式操作实现原理分析

本文实例讲述了PHP对象链式操作实现原理。分享给大家供大家参考,具体如下: 什么是链式操作呢?使用jQuery的同学印象应该会很深刻.在jQuery中,我们经常会这样的来操作DO...

举例详解PHP脚本的测试方法

一、常用测试示例 我们经常会遇到这种情况:将一些没有经过任何测试的遗留代码进行重新编写测试,甚至这些代码还是用面向对象写的。要对这样的代码进行测试,我的建议是把代码分解成块,这样就容易测...

php开发中的页面跳转方法总结

页面跳转可能是由于用户单击链接、按钮等触发的,也可能是系统自动产生的。页面自动跳转在WEB开发中经常用到,而且根据需求可以采用不同的跳转方式,比如提示操作信息后延时跳转等, 本文总结了W...