119 lines
5.2 KiB
PHP
119 lines
5.2 KiB
PHP
<?php
|
|
session_start();
|
|
include_once("db_config.php");
|
|
mysqli_set_charset($link, 'utf8');
|
|
$table = '';
|
|
if ($_SERVER['REQUEST_METHOD'] == 'POST') {
|
|
$operation = $_POST['operation'];
|
|
$table = $_POST['table'];
|
|
if ($operation == 'del') {
|
|
drop_table($link, $table);
|
|
} else if ($operation == 'create') {
|
|
create_table($link, $table);
|
|
} else {
|
|
select_table($link, $table);
|
|
}
|
|
}
|
|
function drop_table($link, $table){
|
|
$query_string = "drop table if exists $table";
|
|
mysqli_query($link,$query_string);
|
|
echo "表删除成功";
|
|
|
|
}
|
|
function create_table($link, $table){
|
|
$result = mysqli_query($link,"show tables like '$table' ");
|
|
if ($result && mysqli_num_rows($result) > 0) {
|
|
$tableExist = true;
|
|
}else{
|
|
$tableExist = false;
|
|
}
|
|
if(!$tableExist){
|
|
if($table == 'user_70'){
|
|
$query_string = "create table user_70(name char(50),address char(50),password char(50))ENGINE=MyISAM DEFAULT CHARSET=utf8";
|
|
mysqli_query($link,$query_string);
|
|
$query_string = "insert into user_70(name,address,password)values('mike','chengdu','c4ca4238a0b923820dcc509a6f75849b')";
|
|
mysqli_query($link,$query_string);
|
|
$query_string = "insert into user_70(name,address,password)values('mike','beijing','c4ca4238a0b923820dcc509a6f75849b')";
|
|
mysqli_query($link,$query_string);
|
|
$query_string = "insert into user_70(name,address,password)values('tom','chengdu','c4ca4238a0b923820dcc509a6f75849b')";
|
|
mysqli_query($link,$query_string);
|
|
$query_string = "insert into user_70(name,address,password)values('rose','chengdu','c4ca4238a0b923820dcc509a6f75849b')";
|
|
mysqli_query($link,$query_string);
|
|
}
|
|
else if($table == 'nucleic_acid_test_2'){
|
|
$eventTime=mktime(12,12,12,12,12,2022);
|
|
$query_string = "create table nucleic_acid_test_2(id varchar(50),name varchar(50),address varchar(50),event_time int,insert_time int,code varchar(1))ENGINE=MyISAM DEFAULT CHARSET=utf8";
|
|
mysqli_query($link,$query_string);
|
|
$query_string = "insert into nucleic_acid_test_2(id,name,address,event_time,insert_time,code)values('510103199010210012','mike','shanghai',$eventTime,'1597238637','3')";
|
|
mysqli_query($link,$query_string);
|
|
$query_string ="insert into nucleic_acid_test_2(id,name,address,event_time,insert_time,code)values('510103198310607013','rose','beijing',$eventTime,'1597242237','2')";
|
|
mysqli_query($link,$query_string);
|
|
}else if($table == 'patient_90'){
|
|
$query_string = "create table patient_90(patient_id char(50),patient_name char(50),patient_gender char(1),patient_address char(50))ENGINE=MyISAM DEFAULT CHARSET=utf8";
|
|
mysqli_query($link,$query_string);
|
|
$query_string = "insert into patient_90 values('123456','王某','1','1')";
|
|
mysqli_query($link,$query_string);
|
|
}
|
|
|
|
select_table($link, $table);
|
|
}else{
|
|
echo "表已存在";
|
|
}
|
|
}
|
|
function select_table($link, $table){
|
|
$result = mysqli_query($link,"show tables like '$table'");
|
|
var_dump($result);
|
|
echo "<br>";
|
|
if ($result && mysqli_num_rows($result) > 0) {
|
|
$tableExist = true;
|
|
}else{
|
|
$tableExist = false;
|
|
}
|
|
if($tableExist){
|
|
if($table == 'user_70'){
|
|
$query_string = "select * from user_70";
|
|
$result = mysqli_query($link,$query_string);
|
|
echo "<div style='font-weight: bold;font-size: 18px;color: red; border-bottom: 1px solid #ccc;padding: 10px'>";
|
|
var_dump($result);
|
|
echo "</div><br>";
|
|
while($row = mysqli_fetch_array($result)){
|
|
echo $row['name']."<br>";
|
|
echo $row['address']."<br>";
|
|
echo $row['password']."<br>";
|
|
echo "<br>";
|
|
}
|
|
}
|
|
else if($table == 'nucleic_acid_test_2'){
|
|
$query_string = "select * from nucleic_acid_test_2";
|
|
$result = mysqli_query($link,$query_string);
|
|
echo "<div style='font-weight: bold;font-size: 18px;color: red; border-bottom: 1px solid #ccc;padding: 10px'>";
|
|
var_dump($result);
|
|
echo "</div><br>";
|
|
while($row = mysqli_fetch_array($result)){
|
|
echo $row['id']."<br>";
|
|
echo $row['name']."<br>";
|
|
echo $row['address']."<br>";
|
|
echo $row['event_time']."<br>";
|
|
echo $row['insert_time']."<br>";
|
|
echo $row['code']."<br>";
|
|
echo "<br>";
|
|
}
|
|
}
|
|
else if($table == 'patient_90'){
|
|
$query_string = "select * from patient_90";
|
|
$result = mysqli_query($link,$query_string);
|
|
echo "<div style='font-weight: bold;font-size: 18px;color: red; border-bottom: 1px solid #ccc;padding: 10px'>";
|
|
var_dump($result);
|
|
echo "</div><br>";
|
|
while($row = mysqli_fetch_array($result)){
|
|
echo $row['patient_id']."<br>";
|
|
echo $row['patient_name']."<br>";
|
|
echo $row['patient_gender']."<br>";
|
|
echo $row['patient_address']."<br>";
|
|
echo "<br>";
|
|
}
|
|
}
|
|
|
|
}
|
|
}
|