第一个页面:
<body>
<p>
<a href='数据库查询.php'>数据库查询</a><p>
<a href="数据库插入.php">数据库插入</a><P>
<a href="数据库修改.php">数据库修改</a><P>
<a href="数据库删除.php">数据库删除</a><P>
</body>
数据库查询页面:
<?php
$con=mysqli_connect("localhost","root","111111","student");//root是我的数据库名,111111是我的数据库密码名,student是数据库
if($con){
echo "连接成功";
}
echo "<table border='4'>";
echo "<tr><td>id</td><td>name</td><td>sex</td><td>address</td></tr>";
$result=mysqli_query($con,"select *from stu");
while($row=mysqli_fetch_array($result)){
echo '<tr><td>'.$row['id']."</td><td>".$row["name"]."</td><td>".$row["sex"]."</td><td>".$row["address"]."</td></tr>";
}
mysqli_free_result($result);
mysqli_close($con);
?>
数据库插入页面:
<?php
$con=mysqli_connect("localhost","root","111111","student");//root是我的数据库名,111111是我的数据库密码名,student是数据库
if(!$con){
die("连接错误");}
echo "连接成功";
echo "<br>";
$sql=mysqli_query($con,"insert into stu(id,name,sex,address)values('1004','小花','女','上海')");
if($sql){
echo "插入成功";
}
mysqli_close($con);
?>
数据库修改页面:
<?php
$con=mysqli_connect("localhost","root","111111","student");//root是我的数据库名,111111是我的数据库密码名,student是数据库
if($con){
echo "连接成功.<p>";
echo "<br>";}
$result=mysqli_query($con,"update stu set name='小可' where address='上海'");
if($result){
echo "修改成功";
}
?>
数据库删除页面:
<?php
$con=mysqli_connect("localhost","root","111111","student");//root是我的数据库名,111111是我的数据库密码名,student是数据库
if($con){
echo "连接成功"."<p>";
}
$result=mysqli_query($con,"delete from stu where name='小花'");
if($result){
echo "删除成功";
}
mysqli_close($con);
?>