最新下载
热门教程
- 1
- 2
- 3
- 4
- 5
- 6
- 7
- 8
- 9
- 10
jsp执行sql语句代码
时间:2009-09-11 编辑:简简单单 来源:一聚教程网
jsp执行sql语句代码
function executesql($operation,$sql)
{
global $db;
if($operation == 'file')
{
require_once PHPCMS_ROOT.'include/upload.class.php';
$savepath = 'data/bakup/';
$upload = new upload('uploadfile',$savepath,'','sql','4096000',1);
if(!$upload->up())
{
showmessage($upload->error());
}
$sql = file_get_contents($upload->uploadedfiles[0][saveto]);
dir_delete($savepath.date('Y'));
if(trim($sql) != '') sql_execute($sql);
}
if(empty($sql))
{
return false;
}
//sql执行
$sql = stripslashes($sql);
$sql = str_replace("\", "", $sql);
$sql = str_replace("r", "", $sql);
$query_items = split(";[ t]{0,}n",$sql);
foreach ($query_items as $key=>$value)
{
if (empty($value))
{
unset($query_items[$key]);
}
}
if(count($query_items) > 1)
{
foreach ($query_items as $key=>$value)
{
if(!$result=$db->query($value, 'SILENT'))
{
return false;
}
}
return true; //退出函数
}
else
{
if (preg_match("/^(?:UPDATE|DELETE|TRUNCATE|ALTER|DROP|FLUSH|INSERT|REPLACE|SET|CREATE)\s+/i", $sql))
{
$result = $db->query($sql);
return $result;
}
else
{
$result = $db->query($sql);
$data=array();
while($r=$db->fetch_array($result))
{
$data[]=$r;
}
return $data;
}
}
}
-
上一个: jsp修改mysql数据表代码
-
下一个: jsp操作文件,删除文件代码
相关文章
- SpringBoot测试配置属性与web启动环境解析 10-24
- vue中将el-switch值true、false改为number类型的1和0解析 10-24
- Vue中的路由配置项meta使用解读 10-24
- SpringBoot自定义bean绑定解析 10-24
- SpringBoot常用计量与bean属性校验和进制数据转换规则解析 10-24
- 工厂方法在Spring框架中的运用介绍 10-24