使用PHP和MySQL专用接口以及ODBC接口

 

实验步骤与内容:

1:安装好PHP的编程环境,我用的编写软件是Epp3mysql

2:在EPP3后编写好Storeandread.php(附带)

3.打开apachemysql

4:在浏览器中打开

http://localhost/Dbconnect/Storeandread.php

使用PHP和MySQL专用接口以及ODBC接口_第1张图片使用PHP和MySQL专用接口以及ODBC接口_第2张图片
<html>
<head><title>储存和读取</title>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" /></head>
<body>
<?php 
$conn=mysqli_connect("localhost" ,"root","266388027","students");
if(empty($conn)){
echo "test";
	die("mysqli_connect failed:".mysqli_connect_error());
} 
//执行插入语句
  $sql="insert into webgrades(class,sid,sname,grade) values ('计算机2002.1','20020100101','王丽',95);";
   $sql1="insert into webgrades(class,sid,sname,grade) values ('计算机2002.2','20020100201','赵宝刚',88);";
    $sql2="insert into webgrades(class,sid,sname,grade) values ('计算机2002.3','20020100301','杜玉',92);";
  $conn->query($sql);
  $conn->query($sql1);
  $conn->query($sql2);
  mysqli_close($conn);
?>
<table width="449" border="1">
<tr>
<th>班级</th><th>学号</th><th>姓名</th><th>成绩</th>
</tr>
<?php 
$conn=mysqli_connect("localhost" ,"root","266388027","students");
if(empty($conn)){
echo "test";
	die("mysqli_connect failed:".mysqli_connect_error());
}   
$sql="select * from webgrades";
$results=$conn->query($sql);
while($row=$results->fetch_row()){
	echo("<tr>");
	echo("<td>".$row[0]."&nbsp;</td>");
	echo("<td>".$row[1]."&nbsp;</td>");
	echo("<td>".$row[2]."&nbsp;</td>");
	echo("<td>".$row[3]."&nbsp;</td>");
	echo("</tr>");
}
mysqli_close($conn);
?>
</table>
</body>
</html>


结论分析与体会:

通过本次实验,了解了怎样配置php运行环境,怎么用php连接上mysql进行简单的操作,同时明白了用phpMyAdmin来管理自己的数据库。收获不少

 

你可能感兴趣的:(apache,PHP,mysql,数据库的简单操作)