程序安装参考例子。
<html xmlns=”http://www.w3.org/1999/xhtml”>
<head>
<meta http-equiv=”Content-Type”content=”text/html; charset=utf-8″/>
<title>php安装小程序</title>
</head>
<body>
<?php
if($_GET[’action’]!=1)
{
?>
<form action=”install.php?action=1″method=”post”>
主机地址:<input type=”text”name=”host”value=”localhost”><br>
用户名:<input type=”text”name=”user”value=”root”><br>
密码:<input type=”password”name=”psw”value=””><br>
新建表名<input type=”text”name=”db”value=”blog”><br>
提交<input type=”submit”name=”sub”value=”提交”/>
</form>
<?php
}
else
{
$lockfile= “install.lock”;
if($_POST[’host’]!=””&& $_POST[’user’]!=””&& $_POST[’ps
w’]!=”” && $_POST[’db’]!=””)
{
$host=$_POST[‘host’];
$user=$_POST[’user’];
$psw=$_POST[’psw’];
$db=$_POST[’db’];
}
if(file_exists($lockfile)){
exit(“已经安装过了,如果要重新安装请先删除install.lock”);
}
$conn=mysql_connect($host,$user,$psw);
if($conn)
{
$sql_drop_db=”Drop DATABASE IF EXISTS `”.$db.”`”;
$sql_create_db=”Create DATABASE `”.$db.”`”;
$sql_create_table_blog=”Create TABLE `blog`.`blog` (
`id` INT( 4 ) NOT NULL AUTO_INCREMENT ,
`con` VARCHAR( 50 ) CHARACTER SET utf8 COLLATE utf8_gener
al_ci NOT NULL ,
PRIMARY KEY ( `id` )
) ENGINE = MYISAM”;
}
mysql_query($sql_drop_db,$conn);
mysql_query($sql_create_db,$conn);
mysql_query($sql_create_table_blog,$conn);
$config_file=”config.php”;
$config_strings=”<?php\n”;
$config_strings.=”\$host=\””.$host.”\”;\n”;
$config_strings.=”\$user=\””.$user.”\”;\n”;
$config_strings.=”\$psw=\””.$psw.”\”;\n”;
$config_strings.=”\$db=\””.$db.”\”;\n”;
$config_strings.=”\$conn=mysql_connect(\$host,\$user,\$psw);\n”;
$config_strings.=”mysql_select_db(\$db,\$conn);\n”;
$config_strings.=”?>”;
$fp=fopen($config_file,”wb”);
fwrite($fp,$config_strings);
fclose($fp);
$fp2= fopen($lockfile,’w’);
fwrite($fp2,’1212′);
fclose($fp2);
}
?>
</body>
</html>
————————————————
原文链接:https://blog.csdn.net/shenpengchao/article/details/56678266