摘要:medoo连接mysql配置<?php //配置medoo require_once __DIR__.'\Medoo-1.6\src\Medoo.php'; use Medoo\Medoo; $arr = [ 'database_type' =>
medoo连接mysql配置
<?php //配置medoo require_once __DIR__.'\Medoo-1.6\src\Medoo.php'; use Medoo\Medoo; $arr = [ 'database_type' => 'mysql', 'database_name' => 'mysqllearn', 'server' => '127.0.0.1', 'username' => 'root', 'password' => 'root' ]; //实例化 $medoo = new Medoo($arr); $table = "user_table_copy2"; //表名 $data = "*"; //字段 $stmt = $medoo->select($table,$data); ?>
<?php @$a = $_REQUEST['oper']; ?>
点击操作
<meta charset="UTF-8">
<?php
include "dd.php";
if ($a == "add"){ ?> <!--//这里的变量act是url地址中的 点击判断查看操作 -->
<style type="text/css">
.tftable {font-size:12px;color:#333333;width:500px;border-width: 1px;border-color: #729ea5;border-collapse: collapse;}
.tftable th {word-break: break-all; word-wrap:break-word;font-size:12px;background-color:#acc8cc;border-width: 1px;padding: 8px;border-style: solid;border-color: #729ea5;text-align:left;}
.tftable tr {background-color:#d4e3e5;}
.tftable td {font-size:12px;border-width: 1px;padding: 8px;border-style: solid;border-color: #729ea5;}
</style>
<!-- 表格 -->
<table class="tftable" border="1" style="width: 500px; height: 50px;">
<tr>
<th>姓名</th>
<th>身高</th>
<th>体重</th>
<th>手机号码</th>
<th>性别</th>
<th>添加</th>
</tr>
<form action="index.php?oper=in_add" method="post">
<tr>
<th><input type="text" name="name"></th>
<th><input type="text" name="height"></th>
<th><input type="text" name="weight"></th>
<th><input type="text" name="phone"></th>
<th><input type="text" name="sex"></th>
<th><input type="submit" value="确认添加"></th>
</tr>
</form>
</table>
<?php }elseif ($a == "in_add"){
$name = $_REQUEST['name'];
$height = $_REQUEST['height'];
$weight = $_REQUEST['weight'];
$phone = $_REQUEST['phone'];
$sex = $_REQUEST['sex'];
$u_id = $_REQUEST['id'];
echo $name.$u_id;
$table = "user_table_copy2";
$data = [
"user_name"=>$name,
"user_height"=>$height,
"user_weight"=>$weight,
"user_phone"=>$phone,
"user_sex"=>$sex
];
$stmt = $medoo->insert($table,$data);
//跳转index首页
if ($stmt){
echo "<script>location.href='index.php'</script>";
}
}elseif ($a == "update"){ ?>
<!-- 表格 -->
<table class="tftable" border="1" style="width: 500px; height: 50px;">
<tr>
<th>修改的id</th>
<th>姓名</th>
<th>身高</th>
<th>体重</th>
<th>手机号码</th>
<th>性别</th>
</tr>
<form action="index.php?oper=in_update" method="post">
<tr>
<th><input type="text" name="id"></th>
<th><input type="text" name="name"></th>
<th><input type="text" name="height"></th>
<th><input type="text" name="weight"></th>
<th><input type="text" name="phone"></th>
<th><input type="text" name="sex"></th>
<th><input type="submit" value="确认修改"></th>
</tr>
</form>
</table>
<?php
}elseif($a == "in_update"){
$table = "user_table_copy2"; //表
$name = $_REQUEST['name'];
$height = $_REQUEST['height'];
$weight = $_REQUEST['weight'];
$phone = $_REQUEST['phone'];
$sex = $_REQUEST['sex'];
$u_id = $_REQUEST['id']; //获取修改的id
$where = ["id[=]" =>$u_id ]; //修改条件
//修改的字段
$data = [
"user_name"=>$name,
"user_height"=>$height,
"user_weight"=>$weight,
"user_phone"=>$phone,
"user_sex"=>$sex
];
$stmt = $medoo->update($table,$data,$where);
if ($stmt){
echo "<script>location.href='index.php'</script>";
}
}elseif ($a == "delete"){ ?>
<table class="tftable" border="1" style="width: 500px; height: 50px;">
<tr>
<th>修改的id</th>
<th>删除</th>
</tr>
<form action="index.php?oper=in_delete" method="post">
<tr>
<th><input type="text" name="id"></th>
<th><input type="submit" value="确认删除"></th>
</tr>
</form>
</table>
<?php }elseif ($a == "in_delete" ){
$id = $_REQUEST['id'];
$table = "user_table_copy2";
$where = ["id[=]"=>$id];
$stmt = $medoo->delete($table,$where);
if ($stmt){
echo "<script>location.href='index.php'</script>";
}
} ?>首页
<?php require __DIR__ . '/connent.php';?>
<?php require __DIR__ . '/Operation.php';?>
<!doctype html>
<html lang="en">
<head>
<meta charset="UTF-8">
<meta name="viewport"
content="width=device-width, user-scalable=no, initial-scale=1.0, maximum-scale=1.0, minimum-scale=1.0">
<meta http-equiv="X-UA-Compatible" content="ie=edge">
<title>用户管理系统</title>
</head>
<body>
<style type="text/css">
.tftable {font-size:12px;color:#333333;width:900px;border-width: 1px;border-color: #729ea5;border-collapse: collapse;}
.tftable th {font-size:12px;background-color:#acc8cc;border-width: 1px;padding: 8px;border-style: solid;border-color: #729ea5;text-align:left;}
.tftable tr {background-color:#d4e3e5;}
.tftable td {font-size:12px;border-width: 1px;padding: 8px;border-style: solid;border-color: #729ea5;}
.tftable tr:hover {background-color:#ffffff;
align:center;}
</style>
<h2 align="center">用户管理</h2>
<table class="tftable" border="1" align="center">
<tr>
<th>id</th>
<th>姓名</th>
<th>身高</th>
<th>体重</th>
<th>手机号码</th>
<th>性别</th>
<th>操作</th>
</tr>
<?php foreach ($stmt as $value)
{
?>
<tr>
<td><?php echo $value['id'] ?></td>
<td><?php echo $value['user_name'] ?></td>
<td><?php echo $value['user_height'] ?></td>
<td><?php echo $value['user_weight'] ?></td>
<td><?php echo $value['user_phone'] ?></td>
<td><?php echo $value['user_sex'] ?></td>
<td>
<a href="index.php?oper=add">添加</a>
<a href="index.php?oper=delete">删除</a>
<a href="index.php?oper=update">修改</a>
</td>
</tr>
<?php
}
?>
<script src="jquery-2.1.1.min.js"></script>
</table>
</body>
</html>



批改老师:韦小宝批改时间:2019-01-18 09:29:07
老师总结:写的非常不错 很棒 代码写的规范没毛病 案例也新奇 继续加油吧