数据库:PHP实验报告

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表格:

数据库:PHP实验报告_第1张图片

(2)创建customers表格:

数据库:PHP实验报告_第2张图片

(3)创建suppliers表格:

数据库:PHP实验报告_第3张图片

(4)创建products表格:

数据库:PHP实验报告_第4张图片

(5)创建purchases表格:

数据库:PHP实验报告_第5张图片

(6)创建logs表格:

数据库:PHP实验报告_第6张图片

(7)向表格中加入具体数据:

数据库:PHP实验报告_第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 "

$tableName | INSERT

"; } ?>

(2)页面效果

数据库:PHP实验报告_第8张图片

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 "";
        }

        echo "";
        echo "";

        while ($dbrow = mysqli_fetch_assoc($res)) {
            echo "";
            foreach ($dbrow as $value) {
                echo "";
            }

            echo "";

            echo "";
        }
        echo "
{$column->name}操作
$value"; echo ""; echo ""; echo ""; echo "
"; } else { echo "No records found in the table."; } } else { echo "Table not specified."; } mysqli_close($conn); ?>

(2)页面效果

数据库:PHP实验报告_第9张图片

数据库:PHP实验报告_第10张图片

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)页面效果:

数据库:PHP实验报告_第11张图片

删除后的表格:

数据库:PHP实验报告_第12张图片

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)页面效果:

数据库:PHP实验报告_第13张图片

数据库:PHP实验报告_第14张图片

修改后的表格为:

数据库:PHP实验报告_第15张图片

6.创建INSERT.php文件实现插入效果:

(1)php代码:




    
    添加EMPLOYEE信息
    


    
请填写要添加EMPLOYEE的信息
cid
cname
city
visits_made
last_visit_time

(2)页面效果:

数据库:PHP实验报告_第16张图片

数据库:PHP实验报告_第17张图片

你可能感兴趣的:(数据库,php,数据库,sql,mysql,php)