Use the following SQL DDL statements to create the six tables required for this project. Note that you need to use the exact statements as shown below to ensure that the instructor can test your programs using the instructor’s data later. Please also note that the tables are created in certain order such that by the time when a foreign key needs to be created, the corresponding primary key has already been created.
1.创建相关表格:
(1)创建employees表格:
(2)创建customers表格:
(3)创建suppliers表格:
(4)创建products表格:
(5)创建purchases表格:
(6)创建logs表格:
(7)向表格中加入具体数据:
2.创建TableList.php实现一个页面显示所有表格:
(1)php代码
显示所有表格
显示所有的表格";
$tablesQuery = "SHOW TABLES";
$tablesResult = mysqli_query($conn, $tablesQuery) or die(mysqli_error($conn));
while ($tableRow = mysqli_fetch_row($tablesResult)) {
$tableName = $tableRow[0];
echo "";
}
?>
(2)页面效果
3.创建show_tables.php实现用户点击某个表名,显示该表的所有信息:
(1)php代码
Contents of Table: $tableName";
$query = "SELECT * FROM $tableName";
$res = mysqli_query($conn, $query) or die(mysqli_error($conn));
if (mysqli_num_rows($res) > 0) {
echo "";
echo "";
$columns = mysqli_fetch_fields($res);
foreach ($columns as $column) {
echo "{$column->name} ";
}
echo "操作 ";
echo " ";
while ($dbrow = mysqli_fetch_assoc($res)) {
echo "";
foreach ($dbrow as $value) {
echo "$value ";
}
echo "";
echo "";
echo "";
echo "";
echo " ";
echo " ";
}
echo "
";
} else {
echo "No records found in the table.";
}
} else {
echo "Table not specified.";
}
mysqli_close($conn);
?>
(2)页面效果
4.创建DELETE.php完成删除记录:
(1)php代码:
true]);
} else {
echo json_encode(['success' => false, 'message' => '数据库中删除记录时发生错误']);
}
mysqli_close($conn);
} else {
echo json_encode(['success' => false, 'message' => '参数无效']);
}
} else {
echo json_encode(['success' => false, 'message' => '无效的请求方法']);
}
?>
(2)页面效果:
删除后的表格:
5.创建CHANGE.php来完成修改记录:
(1)php代码:
$value) {
if ($key != 'table' && $key != 'id') {
$updateValues[] = "$key = '" . mysqli_real_escape_string($conn, $value) . "'";
}
}
$query = "UPDATE $tableName SET " . implode(", ", $updateValues) . " WHERE id = $id";
$result = mysqli_query($conn, $query);
if ($result) {
echo json_encode(['success' => true]);
} else {
echo json_encode(['success' => false, 'message' => '数据库中更新记录时发生错误']);
}
mysqli_close($conn);
} else {
echo json_encode(['success' => false, 'message' => '参数无效']);
}
} else {
echo json_encode(['success' => false, 'message' => '无效的请求方法']);
}
?>
(2)页面效果:
修改后的表格为:
6.创建INSERT.php文件实现插入效果:
(1)php代码:
添加EMPLOYEE信息
请填写要添加EMPLOYEE的信息
(2)页面效果: