下面直接上代码
复制代码 代码如下:
//date_default_timezone_set("Asia/Shanghai");
function create_siteinfo()
{
global $conn;
$sql = "create table siteinfo (
title varchar(100) not null,
keyword varchar(200) not null,
description varchar(200) not null
)";
$dropsql = "drop table if exists siteinfo";
mysql_query($dropsql,$conn)or die("删除表siteinfo失败!");
mysql_query($sql,$conn)or die("创建表siteinfo失败!");
}
function create_article()
{
global $conn,$table_article;
$sql ="create table $table_article(
id int(11) auto_increment not null,
cid int(5) not null,
abstract varchar(300) not null,
title varchar(50) not null,
posttime datetime not null,
author varchar(30) not null,
comefrom varchar(50) not null,
comeurl varchar(50) not null,
content TEXT not null,
keyword varchar(20) not null,
rank int(2) not null,
views int(5) not null,
PRIMARY KEY(id)
)";
$dropsql = "drop table if exists $table_article";
mysql_query($dropsql,$conn)or die("删除数据库失败!");
mysql_query($sql,$conn)or die("创建数据库失败!");
}
function create_member()
{
global $conn,$table_member;
$sql = "create table $table_member(
uid int(5) auto_increment not null,
u_name varchar(20) not null UNIQUE,
u_passwd varchar(100) not null,
rank int(2) not null,
PRIMARY KEY(uid)
)";
$dropsql = "drop table if exists $table_member";
mysql_query($dropsql,$conn)or die("删除数据库失败!");
mysql_query($sql,$conn)or die("创建数据库失败!");
}
function create_class()
{
global $conn,$table_class;
$sql = "create table $table_class(
cid int(5) auto_increment not null,
cname varchar(50) not null UNIQUE,
PRIMARY KEY(cid)
)";
$dropsql = "drop table if exists $table_class";
mysql_query($dropsql,$conn)or die("删除".$table_class."失败!");
mysql_query($sql,$conn)or die("创建表".$table_class."失败");
}
function create_guest()
{
global $conn,$table_guest;
$sql = "create table $table_guest(
gid int(11) auto_increment not null,
g_name varchar(50) not null,
g_site varchar(50) not null,
g_mail varchar(50) not null,
g_cid int(5) not null,
PRIMARY KEY(gid)
)";
$dropsql = "drop table if exists $table_guest";
mysql_query($dropsql,$conn)or die("删除表".$table_guest."失败");
mysql_query($sql,$conn)or die("创建表".$table_guest."失败");
}
function create_sql()
{
global $table_article,$table_member,$table_class,$table_guest,$conn;
echo "创建siteinfo表r……";
create_siteinfo();
echo "完成
";
echo "创建".$table_article."表r……";
create_article();
echo "完成
";
echo "创建".$table_member."表r……";
create_member();
echo "完成
";
echo "创建".$table_class."表r……";
create_class();
echo "完成
";
echo "创建".$table_guest."表r……";
create_guest();
echo "完成
";
mysql_close($conn);
}
?>



