Discuz教程网

创建数据库PHP代码 用PHP写出自己的BLOG系统

[复制链接]
authicon dly 发表于 2011-9-1 10:17:08 | 显示全部楼层 |阅读模式
下面直接上代码
代码如下:

  1. <?php
  2. //date_default_timezone_set("Asia/Shanghai");
  3. /*
  4. function create_siteinfo
  5. DONE:网站信息表
  6. Author:www.5dkx.com
  7. DATE:2010-3-30
  8. 表结构:
  9. title 网站名
  10. keyword 网站关键词
  11. description 网站描述
  12. */
  13. function create_siteinfo()
  14. {
  15. global $conn;
  16. $sql = "create table siteinfo (
  17. title varchar(100) not null,
  18. keyword varchar(200) not null,
  19. description varchar(200) not null
  20. )";
  21. $dropsql = "drop table if exists siteinfo";
  22. mysql_query($dropsql,$conn)or die("删除表siteinfo失败!");
  23. mysql_query($sql,$conn)or die("创建表siteinfo失败!");
  24. }
  25. /*
  26. function:create_article()
  27. DONE:mysql创建文章表sql语句
  28. Author:www.5dkx.com
  29. 表结构:
  30. id 文章ID
  31. cid 归属类别ID
  32. abstract 文章摘要
  33. title 文章标题
  34. posttime 发布时间
  35. aurhor 作者
  36. comefrom 文章来源
  37. comeurl 来源URL
  38. content 正文内容
  39. keyword 关键词
  40. rank 文章等级
  41. views 浏览次数
  42. */
  43. function create_article()
  44. {
  45. global $conn,$table_article;
  46. $sql ="create table $table_article(
  47. id int(11) auto_increment not null,
  48. cid int(5) not null,
  49. abstract varchar(300) not null,
  50. title varchar(50) not null,
  51. posttime datetime not null,
  52. author varchar(30) not null,
  53. comefrom varchar(50) not null,
  54. comeurl varchar(50) not null,
  55. content TEXT not null,
  56. keyword varchar(20) not null,
  57. rank int(2) not null,
  58. views int(5) not null,
  59. PRIMARY KEY(id)
  60. )";
  61. $dropsql = "drop table if exists $table_article";
  62. mysql_query($dropsql,$conn)or die("删除数据库失败!");
  63. mysql_query($sql,$conn)or die("创建数据库失败!");
  64. }
  65. /*
  66. function:create_member()
  67. DONE:mysql创建会员表sql语句
  68. Author:www.5dkx.com
  69. uid 会员ID
  70. u_name 会员名称
  71. u_passwd 密码
  72. rank 会员等级
  73. */
  74. function create_member()
  75. {
  76. global $conn,$table_member;
  77. $sql = "create table $table_member(
  78. uid int(5) auto_increment not null,
  79. u_name varchar(20) not null UNIQUE,
  80. u_passwd varchar(100) not null,
  81. rank int(2) not null,
  82. PRIMARY KEY(uid)
  83. )";
  84. $dropsql = "drop table if exists $table_member";
  85. mysql_query($dropsql,$conn)or die("删除数据库失败!");
  86. mysql_query($sql,$conn)or die("创建数据库失败!");
  87. }
  88. /*
  89. function:create_class
  90. DONE:sql创建分类sql语句
  91. Author:www.5dkx.com
  92. 表结构:
  93. cid 类类别ID
  94. cname 类名
  95. */
  96. function create_class()
  97. {
  98. global $conn,$table_class;
  99. $sql = "create table $table_class(
  100. cid int(5) auto_increment not null,
  101. cname varchar(50) not null UNIQUE,
  102. PRIMARY KEY(cid)
  103. )";
  104. $dropsql = "drop table if exists $table_class";
  105. mysql_query($dropsql,$conn)or die("删除".$table_class."失败!");
  106. mysql_query($sql,$conn)or die("创建表".$table_class."失败");
  107. }
  108. /*
  109. function:create_guest
  110. DONE:sql创建留言板sql语句
  111. Author:www.5dkx.com
  112. 表结构:
  113. gid 留言ID
  114. g_name 留言用户名
  115. g_site 用户个人主页
  116. g_mail 用户邮箱
  117. g_cid 留言位置(哪篇文章或者是留言板)
  118. */
  119. function create_guest()
  120. {
  121. global $conn,$table_guest;
  122. $sql = "create table $table_guest(
  123. gid int(11) auto_increment not null,
  124. g_name varchar(50) not null,
  125. g_site varchar(50) not null,
  126. g_mail varchar(50) not null,
  127. g_cid int(5) not null,
  128. PRIMARY KEY(gid)
  129. )";
  130. $dropsql = "drop table if exists $table_guest";
  131. mysql_query($dropsql,$conn)or die("删除表".$table_guest."失败");
  132. mysql_query($sql,$conn)or die("创建表".$table_guest."失败");
  133. }
  134. function create_sql()
  135. {
  136. global $table_article,$table_member,$table_class,$table_guest,$conn;
  137. echo "创建siteinfo表\r……";
  138. create_siteinfo();
  139. echo "完成<br>";
  140. echo "创建".$table_article."表\r……";
  141. create_article();
  142. echo "完成<br>";
  143. echo "创建".$table_member."表\r……";
  144. create_member();
  145. echo "完成<br>";
  146. echo "创建".$table_class."表\r……";
  147. create_class();
  148. echo "完成<br>";
  149. echo "创建".$table_guest."表\r……";
  150. create_guest();
  151. echo "完成<br>";
  152. mysql_close($conn);
  153. }
  154. ?>
复制代码








上一篇:在IIS7.0下面配置PHP 5.3.2运行环境的方法
下一篇:创建配置文件 用PHP写出自己的BLOG系统 2
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

1314学习网 ( 浙ICP备10214163号 )

GMT+8, 2025-5-2 11:29

Powered by Discuz! X3.4

© 2001-2013 Comsenz Inc.

快速回复 返回顶部 返回列表