假设我的的数据库名称为info, 数据库在本地127.0.0.1或者localhost,其中我们网站所要安装的是info数据库和其中的articles表,则我们的自动安装的方法为:
1.假设info.sql中记录articles表,内容为:
create table if not exists articles
(
article_id not null primary auto_increment,
aritlce_name varchar(20)
…….
)
2.实现的原理,使用mysql_query()来执行相关的sql语句
<?php
$con=mysql_connect(“127.0.0.1″,”root”,”123″);//连接数据库
mysql_select_db(“info”,$con);//选择info数据库
mysql_query(“set names gb2312″);//设置编码
$sql=file_get_contents(“info.sql”);//获取相关的sql语句,因为文件中只有一条sql语句,因此不涉及相关语句的分割
$result=mysql_query($sql);
if($result)
echo “安装成功”;
else
echo “安装失败”;
?>
1f742a0a
相关文章:
Comments
Leave a comment Trackback