优化 数据库连接

This commit is contained in:
LyLme 2022-03-12 15:38:17 +08:00
parent b869f1b140
commit a3046f3b6b
2 changed files with 78 additions and 95 deletions

View File

@ -1,7 +1,7 @@
<?php <?php
$title='搜索引擎设置'; $title='搜索引擎设置';
include './head.php'; include './head.php';
$sousrows=mysqli_num_rows(mysqli_query($con, "SELECT * FROM `lylme_sou`")); $sousrows=$DB->num_rows($DB->query("SELECT * FROM `lylme_sou`"));
?> ?>
<main class="lyear-layout-content"> <main class="lyear-layout-content">
@ -72,8 +72,9 @@ echo '<h4>新增搜索接</h4>
elseif($set=='edit') elseif($set=='edit')
{ {
$id=$_GET['id']; $id=$_GET['id'];
$row2 = mysqli_query($con,"select * from lylme_sou where sou_id='$id' limit 1");
$row=mysqli_fetch_assoc($row2); $row2 = $DB->query("select * from lylme_sou where sou_id='$id' limit 1");
$row= $DB->fetch($row2);
echo '<h4>修改搜索引擎</h4> echo '<h4>修改搜索引擎</h4>
<div class="panel-body"> <div class="panel-body">
<form action="./sou.php?set=edit_submit&id='.$id.'" method="POST"> <form action="./sou.php?set=edit_submit&id='.$id.'" method="POST">
@ -153,8 +154,7 @@ $sql="INSERT INTO `lylme_sou` (`sou_id`, `sou_alias`, `sou_name`, `sou_hint`, `s
(NULL, '".$alias."', '".$name."', '".$hint."', '".$color."', '".$link."', '".$waplink."', '".$icon."', '".$st."', '".$sou_order."'); (NULL, '".$alias."', '".$name."', '".$hint."', '".$color."', '".$link."', '".$waplink."', '".$icon."', '".$st."', '".$sou_order."');
"; ";
if($DB->query($sql)){
if(mysqli_query($con,$sql)){
echo '<script>alert("添加搜索引擎 '.$name.' 成功!");window.location.href="/admin/sou.php";</script>'; echo '<script>alert("添加搜索引擎 '.$name.' 成功!");window.location.href="/admin/sou.php";</script>';
}else }else
echo '<script>alert("添加搜索引擎失败!");history.go(-1);</script>'; echo '<script>alert("添加搜索引擎失败!");history.go(-1);</script>';
@ -163,8 +163,8 @@ if(mysqli_query($con,$sql)){
elseif($set=='edit_submit') elseif($set=='edit_submit')
{ {
$id=$_GET['id']; $id=$_GET['id'];
$rows2 = mysqli_query($con,"select * from lylme_sou where sou_id='$id' limit 1"); $rows2 = $DB->query("select * from lylme_sou where sou_id='$id' limit 1");
$rows=mysqli_fetch_assoc($rows2); $rows=$DB->fetch($rows2);
if(!$rows) if(!$rows)
echo '<script>alert("当前记录不存在!");history.go(-1);</script>'; echo '<script>alert("当前记录不存在!");history.go(-1);</script>';
$name=$_POST['name']; $name=$_POST['name'];
@ -183,7 +183,8 @@ if (empty($name) && empty($alias)&& empty($hint) && empty($link) && empty($color
$sql="UPDATE `lylme_sou` SET `sou_alias` = '".$alias."', `sou_name` = '".$name."', `sou_hint` = '".$hint."', `sou_color` = '".$color."', `sou_link` = '".$link."', `sou_waplink` = '".$waplink."', `sou_icon` = '".$icon."', `sou_st` = '".$st."', `sou_order` = '".$order."' WHERE `lylme_sou`.`sou_id` = ".$id.";"; $sql="UPDATE `lylme_sou` SET `sou_alias` = '".$alias."', `sou_name` = '".$name."', `sou_hint` = '".$hint."', `sou_color` = '".$color."', `sou_link` = '".$link."', `sou_waplink` = '".$waplink."', `sou_icon` = '".$icon."', `sou_st` = '".$st."', `sou_order` = '".$order."' WHERE `lylme_sou`.`sou_id` = ".$id.";";
if(mysqli_query($con,$sql))
if($DB->query($sql))
echo '<script>alert("修改搜索引擎 '.$name.' 成功!");window.location.href="/admin/sou.php";</script>'; echo '<script>alert("修改搜索引擎 '.$name.' 成功!");window.location.href="/admin/sou.php";</script>';
else else
echo '<script>alert("修改失败!");history.go(-1);</script>'; echo '<script>alert("修改失败!");history.go(-1);</script>';
@ -193,7 +194,7 @@ elseif($set=='delete')
{ {
$id=$_GET['id']; $id=$_GET['id'];
$sql="DELETE FROM lylme_sou WHERE sou_id='$id'"; $sql="DELETE FROM lylme_sou WHERE sou_id='$id'";
if(mysqli_query($con,$sql)) if($DB->query($sql))
echo '<script>alert("删除成功!");window.location.href="/admin/sou.php";</script>'; echo '<script>alert("删除成功!");window.location.href="/admin/sou.php";</script>';
else else
echo '<script>alert("删除失败!");history.go(-1);</script>'; echo '<script>alert("删除失败!");history.go(-1);</script>';
@ -204,9 +205,10 @@ echo '<div class="alert alert-info">系统共有 <b>'.$sousrows.'</b> 个搜索
<table class="table table-striped"> <table class="table table-striped">
<thead><tr><th>排序权重</th><th>名称</th><th>别名</th><th>地址</th><th>状态</th><th>操作</th></tr></thead> <thead><tr><th>排序权重</th><th>名称</th><th>别名</th><th>地址</th><th>状态</th><th>操作</th></tr></thead>
<tbody>'; <tbody>';
$rs=mysqli_query($con,"SELECT * FROM `lylme_sou` ORDER BY `lylme_sou`.`sou_order` ASC");
while($res = mysqli_fetch_array($rs)) $rs=$DB->query("SELECT * FROM `lylme_sou` ORDER BY `lylme_sou`.`sou_order` ASC");
while($res = $DB->fetch($rs))
{ {
echo '<tr><td><b>'.$res['sou_order'].'</b></td><td><b><font color="'.$res['sou_color'].'">'.$res['sou_name'].'</font></b></td><td>'.$res['sou_alias'].'</td><td>'.$res['sou_link'].'</td><td>'; echo '<tr><td><b>'.$res['sou_order'].'</b></td><td><b><font color="'.$res['sou_color'].'">'.$res['sou_name'].'</font></b></td><td>'.$res['sou_alias'].'</td><td>'.$res['sou_link'].'</td><td>';

View File

@ -1,7 +1,7 @@
<?php <?php
$title='导航菜单管理'; $title = '导航菜单管理';
include './head.php'; include './head.php';
$tagsrows=mysqli_num_rows(mysqli_query($con, "SELECT * FROM `lylme_tags`")); $tagsrows = $DB->num_rows($DB->query("SELECT * FROM `lylme_tags`"));
?> ?>
<main class="lyear-layout-content"> <main class="lyear-layout-content">
@ -12,12 +12,9 @@ $tagsrows=mysqli_num_rows(mysqli_query($con, "SELECT * FROM `lylme_tags`"));
<div class="card"> <div class="card">
<div class="card-body"> <div class="card-body">
<?php <?php
$set = isset($_GET['set']) ? $_GET['set'] : null;
$set=isset($_GET['set'])?$_GET['set']:null; if ($set == 'add') {
echo '<h4>新增导航菜单链接</h4>
if($set=='add')
{
echo '<h4>新增导航菜单链接</h4>
<div class="panel-body"> <div class="panel-body">
<form action="./tag.php?set=add_submit" method="POST"> <form action="./tag.php?set=add_submit" method="POST">
<div class="form-group"> <div class="form-group">
@ -39,102 +36,88 @@ echo '<h4>新增导航菜单链接</h4>
</div> </div>
<br/><a href="./tag.php"><<返回</a> <br/><a href="./tag.php"><<返回</a>
</div></div>'; </div></div>';
} } elseif ($set == 'edit') {
elseif($set=='edit') $id = $_GET['id'];
{ $row2 = $DB->query("select * from lylme_tags where tag_id='$id' limit 1");
$id=$_GET['id']; $row = $DB->fetch($row2);
$row2 = mysqli_query($con,"select * from lylme_tags where tag_id='$id' limit 1"); echo '<h4>修改导航菜单链接</h4>
$row=mysqli_fetch_assoc($row2);
echo '<h4>修改导航菜单链接</h4>
<div class="panel-body"> <div class="panel-body">
<form action="./tag.php?set=edit_submit&id='.$id.'" method="POST"> <form action="./tag.php?set=edit_submit&id=' . $id . '" method="POST">
<div class="form-group"> <div class="form-group">
<label>*名称:</label><br> <label>*名称:</label><br>
<input type="text" class="form-control" name="name" value="'.$row['tag_name'].'" required> <input type="text" class="form-control" name="name" value="' . $row['tag_name'] . '" required>
</div> </div>
<div class="form-group"> <div class="form-group">
<label>*链接地址:</label><br> <label>*链接地址:</label><br>
<input type="text" class="form-control" name="link" value="'.$row['tag_link'].'" required> <input type="text" class="form-control" name="link" value="' . $row['tag_link'] . '" required>
</div> </div>
<div class="form-group"> <div class="form-group">
<label>*打开方式:</label><br> <label>*打开方式:</label><br>
<select class="form-control" name="target"> <select class="form-control" name="target">
<option value="0">0. 当前窗口打开</option> <option value="0">0. 当前窗口打开</option>
<option '; <option ';
if($row['tag_target']==1){ if ($row['tag_target'] == 1) {
echo 'selected="selected"';} echo 'selected="selected"';
echo 'value="1">1. 新窗口打开</option> }
echo 'value="1">1. 新窗口打开</option>
</select></div> </select></div>
<div class="form-group"> <div class="form-group">
<input type="submit" class="btn btn-primary btn-block" value="修改"></form> <input type="submit" class="btn btn-primary btn-block" value="修改"></form>
</div> </div>
<br/><a href="./tag.php"><<返回</a> <br/><a href="./tag.php"><<返回</a>
</div></div>'; </div></div>';
} } elseif ($set == 'add_submit') {
elseif($set=='add_submit') $name = $_POST['name'];
{ $link = $_POST['link'];
$name=$_POST['name']; if ($_POST['target'] == true) {
$target = 1;
$link=$_POST['link']; } else {
if($_POST['target']==true){$target=1;}else{$target=0;} $target = 0;
if($name==NULL or $link==NULL){ }
echo '<script>alert("保存错误,请确保带星号的都不为空!");history.go(-1);</script>'; if ($name == NULL or $link == NULL) {
echo '<script>alert("保存错误,请确保带星号的都不为空!");history.go(-1);</script>';
} else {
$sql = "INSERT INTO `lylme_tags` (`tag_id`, `tag_name`, `tag_link`, `tag_target`) VALUES (NULL, '" . $name . "', '" . $link . "', '" . $target . "');";
if ($DB->query($sql)) {
echo '<script>alert("添加导航菜单 ' . $name . ' 成功!");window.location.href="/admin/tag.php";</script>';
} else echo '<script>alert("添加导航菜单失败");history.go(-1);</script>';
}
} elseif ($set == 'edit_submit') {
$id = $_GET['id'];
$rows2 = $DB->query("select * from lylme_tags where tag_id='$id' limit 1");
$rows = $DB->fetch($rows2);
if (!$rows) echo '<script>alert("当前记录不存在!");history.go(-1);</script>';
$name = $_POST['name'];
$link = $_POST['link'];
if ($_POST['target'] == true) {
$target = 1;
} else {
$target = 0;
}
if ($name == NULL or $link == NULL) {
echo '<script>alert("保存错误,请确保带星号的都不为空!");history.go(-1);</script>';
} else {
$sql = "UPDATE `lylme_tags` SET `tag_name` = '" . $name . "', `tag_link` = '" . $link . "', `tag_target` = '" . $target . "' WHERE `lylme_tags`.`tag_id` = " . $id . ";";
if ($DB->query($sql)) echo '<script>alert("修改导航菜单 ' . $name . ' 成功!");window.location.href="/admin/tag.php";</script>';
else echo '<script>alert("修改导航菜单失败!");history.go(-1);</script>';
}
} elseif ($set == 'delete') {
$id = $_GET['id'];
$sql = "DELETE FROM lylme_tags WHERE tag_id='$id'";
if ($DB->query($sql)) echo '<script>alert("删除成功!");window.location.href="/admin/tag.php";</script>';
else echo '<script>alert("删除失败!");history.go(-1);</script>';
} else { } else {
$sql="INSERT INTO `lylme_tags` (`tag_id`, `tag_name`, `tag_link`, `tag_target`) VALUES (NULL, '".$name."', '".$link."', '".$target."');"; echo '<div class="alert alert-info">系统共有 <b>' . $tagsrows . '</b> 个导航菜单<br/><a href="./tag.php?set=add" class="btn btn-primary">新增导航菜单</a></div>';
if(mysqli_query($con,$sql)){
echo '<script>alert("添加导航菜单 '.$name.' 成功!");window.location.href="/admin/tag.php";</script>';
}else
echo '<script>alert("添加导航菜单失败");history.go(-1);</script>';
}
}
elseif($set=='edit_submit')
{
$id=$_GET['id'];
$rows2 = mysqli_query($con,"select * from lylme_tags where tag_id='$id' limit 1");
$rows=mysqli_fetch_assoc($rows2);
if(!$rows)
echo '<script>alert("当前记录不存在!");history.go(-1);</script>';
$name=$_POST['name'];
$link=$_POST['link'];
if($_POST['target']==true){$target=1;}else{$target=0;}
if($name==NULL or $link==NULL){
echo '<script>alert("保存错误,请确保带星号的都不为空!");history.go(-1);</script>';
} else {
$sql = "UPDATE `lylme_tags` SET `tag_name` = '".$name."', `tag_link` = '".$link."', `tag_target` = '".$target."' WHERE `lylme_tags`.`tag_id` = ".$id.";";
if(mysqli_query($con,$sql))
echo '<script>alert("修改导航菜单 '.$name.' 成功!");window.location.href="/admin/tag.php";</script>';
else
echo '<script>alert("修改导航菜单失败!");history.go(-1);</script>';
}
}
elseif($set=='delete')
{
$id=$_GET['id'];
$sql="DELETE FROM lylme_tags WHERE tag_id='$id'";
if(mysqli_query($con,$sql))
echo '<script>alert("删除成功!");window.location.href="/admin/tag.php";</script>';
else
echo '<script>alert("删除失败!");history.go(-1);</script>';
}
else
{
echo '<div class="alert alert-info">系统共有 <b>'.$tagsrows.'</b> 个导航菜单<br/><a href="./tag.php?set=add" class="btn btn-primary">新增导航菜单</a></div>';
?> ?>
<div class="table-responsive"> <div class="table-responsive">
<table class="table table-striped"> <table class="table table-striped">
<thead><tr><th>名称</th><th>链接</th><th>操作</th></tr></thead> <thead><tr><th>名称</th><th>链接</th><th>操作</th></tr></thead>
<tbody> <tbody>
<?php <?php
$rs=mysqli_query($con,"SELECT * FROM `lylme_tags`"); $rs = $DB->query("SELECT * FROM `lylme_tags`");
while($res = mysqli_fetch_array($rs)) while ($res = $DB->fetch($rs)) {
{ echo '<tr><td>' . $res['tag_name'] . '</td><td>' . $res['tag_link'] . '</td><td><a href="./tag.php?set=edit&id=' . $res['tag_id'] . '" class="btn btn-info btn-xs">编辑</a>&nbsp;<a href="./tag.php?set=delete&id=' . $res['tag_id'] . '" class="btn btn-xs btn-danger" onclick="return confirm(\'确定删除 ' . $res['tag_name'] . ' \');">删除</a></td></tr>';
echo '<tr><td>'.$res['tag_name'].'</td><td>'.$res['tag_link'].'</td><td><a href="./tag.php?set=edit&id='.$res['tag_id'].'" class="btn btn-info btn-xs">编辑</a>&nbsp;<a href="./tag.php?set=delete&id='.$res['tag_id'].'" class="btn btn-xs btn-danger" onclick="return confirm(\'确定删除 '.$res['tag_name'].' \');">删除</a></td></tr>'; }
}
?> ?>
</tbody> </tbody>
</table> </table>
@ -148,9 +131,7 @@ echo '<tr><td>'.$res['tag_name'].'</td><td>'.$res['tag_link'].'</td><td><a href=
</div> </div>
</main> </main>
<?php <?php
} }
include './footer.php'; include './footer.php';
?> ?>