数据库操作
2016-06-27 18:27
295 查看
首先举一个示例吧!这里有一个学生表表格(用html),显示学生的基本信息,所以就得先从数据库中取出信息,这是对数据操作的前提,因为不取出信息,那你是对谁操作呢?
<!-- 请根据以下代码自己设计数据库 --> /*connect.php*/ <?php $conn=mysql_connect("localhost","root","root") or die("数据库连接失败"); $select_db=mysql_select_db("test") or die("数据库选择失败"); mysql_query("set names utf8");//设置字符集 //注意顺序 $select_db="select *from stu order by stu_id"; $result=mysql_query($select_db); if(!$result)
/*table.php*/ <html> <head> <title>table</title> <meta charset="utf-8" /> </head> <body> <center> <table width='30%' align='center' border='1'> <tr> <td colspan='6' align='left'><a href='insert.php'><input name="return" type="button" value="添加" ></a></a></td> </tr> <tr> <td colspan='6' align='center'>学生信息表</td> </tr> <tr bgcolor='pink'> <td>编号</td> <td>姓名</td> <td>年龄</td> <td>性别</td> <td colspan=2 align='center'>操作</td> </tr> <?php include("connect.php"); //包含数据连接 while($row=mysql_fetch_array($result)) { ?> <tr> <td><?php echo $row['stu_id'];?></td> <td><a href='show.php?ud=<?php echo $row["stu_id"];?>'><?php echo $row['stu_name'];?></a></td> <td><?php echo $row['stu_age'];?></td> <td><?php echo $row['stu_sex'];?></td> <td align='center'><a href='edit.php?ud=<?php echo $row["stu_id"];?>'><input name="return" type="button" value="编辑" ></a></td> <td align='center'><a href='delete.php?ud=<?php echo $row["stu_id"];?>'><input name="return" type="button" value="删除" ></a></td> </tr> <?php } ?> </table> <?php mysql_close($conn); //关闭数据库 ?> </center> </body> </html> 以上两个代码实现显示信息
{ echo 'SQL语句操作失败'; mysql_error(); } ?>
相关文章推荐
- oracle
- 【Mysql】mysql查询超时JDBC源码浅析
- jsp中使用动态数据进行mySQL数据库的两种操作方法
- mysqldump和mydumper的比较
- MYSQL性能查看(命中率,慢查询)
- 数据库事务的理解
- TimesTen 数据库复制学习:8. 管理Active Standby Pair(带缓存组)
- MySQL 索引分析
- window下mysql安装以及问题解决方法
- myBatis数据库连接配置错误
- oracle中的替换函数replace和translate函数
- MySQL出现SQL Error (2013)连接错误的解决方法
- MySQL行级锁、表级锁、页级锁详细介绍
- 时间序列数据库的秘密(3)——加载和分布式计算
- 数据库范式
- mybatis学习笔记(四)SQL映射语句
- 时间序列数据库的秘密(2)——索引
- Java的JSON操作存储List到Redis
- 时间序列数据库的秘密(1)—— 介绍
- mysql分表技术(学习心得)