优化 数据库连接

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
$title='搜索引擎设置';
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">
@ -72,8 +72,9 @@ echo '<h4>新增搜索接</h4>
elseif($set=='edit')
{
$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>
<div class="panel-body">
<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."');
";
if(mysqli_query($con,$sql)){
if($DB->query($sql)){
echo '<script>alert("添加搜索引擎 '.$name.' 成功!");window.location.href="/admin/sou.php";</script>';
}else
echo '<script>alert("添加搜索引擎失败!");history.go(-1);</script>';
@ -163,8 +163,8 @@ if(mysqli_query($con,$sql)){
elseif($set=='edit_submit')
{
$id=$_GET['id'];
$rows2 = mysqli_query($con,"select * from lylme_sou where sou_id='$id' limit 1");
$rows=mysqli_fetch_assoc($rows2);
$rows2 = $DB->query("select * from lylme_sou where sou_id='$id' limit 1");
$rows=$DB->fetch($rows2);
if(!$rows)
echo '<script>alert("当前记录不存在!");history.go(-1);</script>';
$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.";";
if(mysqli_query($con,$sql))
if($DB->query($sql))
echo '<script>alert("修改搜索引擎 '.$name.' 成功!");window.location.href="/admin/sou.php";</script>';
else
echo '<script>alert("修改失败!");history.go(-1);</script>';
@ -193,7 +194,7 @@ elseif($set=='delete')
{
$id=$_GET['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>';
else
echo '<script>alert("删除失败!");history.go(-1);</script>';
@ -205,8 +206,9 @@ echo '<div class="alert alert-info">系统共有 <b>'.$sousrows.'</b> 个搜索
<thead><tr><th>排序权重</th><th>名称</th><th>别名</th><th>地址</th><th>状态</th><th>操作</th></tr></thead>
<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>';

View File

@ -1,7 +1,7 @@
<?php
$title='导航菜单管理';
$title = '导航菜单管理';
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">
@ -12,12 +12,9 @@ $tagsrows=mysqli_num_rows(mysqli_query($con, "SELECT * FROM `lylme_tags`"));
<div class="card">
<div class="card-body">
<?php
$set=isset($_GET['set'])?$_GET['set']:null;
if($set=='add')
{
echo '<h4>新增导航菜单链接</h4>
$set = isset($_GET['set']) ? $_GET['set'] : null;
if ($set == 'add') {
echo '<h4>新增导航菜单链接</h4>
<div class="panel-body">
<form action="./tag.php?set=add_submit" method="POST">
<div class="form-group">
@ -39,102 +36,88 @@ echo '<h4>新增导航菜单链接</h4>
</div>
<br/><a href="./tag.php"><<返回</a>
</div></div>';
}
elseif($set=='edit')
{
$id=$_GET['id'];
$row2 = mysqli_query($con,"select * from lylme_tags where tag_id='$id' limit 1");
$row=mysqli_fetch_assoc($row2);
echo '<h4>修改导航菜单链接</h4>
} elseif ($set == 'edit') {
$id = $_GET['id'];
$row2 = $DB->query("select * from lylme_tags where tag_id='$id' limit 1");
$row = $DB->fetch($row2);
echo '<h4>修改导航菜单链接</h4>
<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">
<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 class="form-group">
<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 class="form-group">
<label>*打开方式:</label><br>
<select class="form-control" name="target">
<option value="0">0. 当前窗口打开</option>
<option ';
if($row['tag_target']==1){
echo 'selected="selected"';}
echo 'value="1">1. 新窗口打开</option>
if ($row['tag_target'] == 1) {
echo 'selected="selected"';
}
echo 'value="1">1. 新窗口打开</option>
</select></div>
<div class="form-group">
<input type="submit" class="btn btn-primary btn-block" value="修改"></form>
</div>
<br/><a href="./tag.php"><<返回</a>
</div></div>';
}
elseif($set=='add_submit')
{
$name=$_POST['name'];
$link=$_POST['link'];
if($_POST['target']==true){$target=1;}else{$target=0;}
if($name==NULL or $link==NULL){
} elseif ($set == 'add_submit') {
$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="INSERT INTO `lylme_tags` (`tag_id`, `tag_name`, `tag_link`, `tag_target`) VALUES (NULL, '".$name."', '".$link."', '".$target."');";
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){
} 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 {
$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>';
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">
<table class="table table-striped">
<thead><tr><th>名称</th><th>链接</th><th>操作</th></tr></thead>
<tbody>
<?php
$rs=mysqli_query($con,"SELECT * FROM `lylme_tags`");
while($res = mysqli_fetch_array($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>';
}
$rs = $DB->query("SELECT * FROM `lylme_tags`");
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>';
}
?>
</tbody>
</table>
@ -149,8 +132,6 @@ echo '<tr><td>'.$res['tag_name'].'</td><td>'.$res['tag_link'].'</td><td><a href=
</main>
<?php
}
include './footer.php';
?>