PHP连接数据库练习

By admin, 30 十一月, 2016

在上一个练习中,我们掌握了怎样用PHP去生成一个表格页面。现在,我们要把表格的内容放到数据库里,PHP先从数据库获取内容,再输出。

学号 姓名 年级 班别
1101 陈一 一年级 1
1102 袁二 一年级 1
1203 张三 一年级 2
2104 李四 二年级 1
2205 王五 二年级 2

步骤大致如下:

  1. 先在PhpMyAdmin里建立MySQL数据库、数据表,输入以上表格数据。
  2. 通过PHP连接MySQL数据库,参考:http://www.w3school.com.cn/php/php_mysql_connect.asp
  3. 执行SELECT语句,把数据表的内容从MySQL数据库拿下来,参考:http://www.w3school.com.cn/php/php_mysql_select.asp
  4. 拿下来之后通过var_dump验证数据正确拿到了,参考:http://php.net/manual/zh/function.var-dump.php
  5. 然后把数据组装成表格输出,步骤3的参考页面也有例子。

评论

Restricted HTML

  • 允许的HTML标签:<a href hreflang> <em> <strong> <cite> <blockquote cite> <code> <ul type> <ol start type> <li> <dl> <dt> <dd> <h2 id> <h3 id> <h4 id> <h5 id> <h6 id> <img src>
  • 自动断行和分段。
  • 网页和电子邮件地址自动转换为链接。
验证码
This question is for testing whether or not you are a human visitor and to prevent automated spam submissions.
请输入"Drupal10"