如何做一个PHP自动安装程序install。php
1月1日 碎骨族投稿 头条创作挑战赛
PHP中有很多优秀的作品,为了让人们更好的安装使用,都会有一个安装引导页面,那这个页面是如何实现的呢?基本功能:
1、生成一个conntent。php的数据库链接文件
2、生成install。lock校验文件,防止二次安装
3、自定义表名前缀,防止表名重复并且保证可读性install。php代码:htmlxmlnshttp:www。w3。org1999xhtmlheadmetahttpequivContentTcharsetutf8titlephp安装程序?phpif(GET〔action〕!1){??php}else{lockfileinstall。if(POST〔host〕!POST〔user〕!POST〔psw〕!POST〔db〕!POST〔mdb〕!){hostPOST〔host〕;userPOST〔user〕;pswPOST〔psw〕;dbPOST〔db〕;mdbPOST〔mdb〕;}if(fileexists(lockfile)){exit(已经安装过了,如果要重新安装请先删除install。lock);}connmysqliconnect(host,user,psw,db);if(!conn){die(连接失败:。mysqliconnecterror());}echo15数据库连接成功;mdbamdb。sqlCREATETABLE{mdba}(idINT(10)UNSIGNEDAUTOINCREMENTPRIMARYKEY,usernameVARCHAR(255)NOTNULL,contentVARCHAR(255),telVARCHAR(255)NOTNULL,wxVARCHAR(255),intimeINT(10)NOTNULL,emailVARCHAR(255));if(mysqliquery(conn,sql)){echo25数据表{mdba}创建成功;}else{die(创建数据表错误:。mysqlierror(conn));}mysqliclose(conn);echo35数据库操作成功;configfileconntent。?configstrings。host。host。;;configstrings。user。user。;;configstrings。pwd。psw。;;configstrings。dbname。db。;;configstrings。dbnewmysqli(host,user,pwd,dbname);;configstrings。tablename。mdba。;;configstrings。if(dbconnecterron0){;configstrings。echo连接失败;;configstrings。};configstrings。dbquery(SETNAMESUTF8);;configstrings。?;fpfopen(configfile,wb);fwrite(fp,configstrings);fclose(fp);echo45数据库文件添加成功;fp2fopen(lockfile,w);fwrite(fp2,安装效验文件);fclose(fp2);echo55效验文件添加成功;}?bodyhtml
页面截图:
安装成功后截图: