php写ecshop安装

大家都知道在解压ecshop模板的时候会出现一个安装检测以及过程,这个功能是怎么实现的那?现在咱们就一起来体验一把!!

以下这个页面是检测你本地的php,操作系统,mysql之类的;


上边的这个关于程序安装目录上传限制,php版本之类的大家去百度搜一下就能出来,这我就不介绍了;

在跳到登陆界面之中时最重要的就是数据库的生成:首先数据库的生成是要在你显示页面写出检测唯一性或者检测是否有值的;界面就是下边的这个:


在安装之后会生成一个文件,我们就是通过这个文件来判断,用户是否安装ecshop并生成数据库的;

 if(is_file("../sql/anzhuang.php")){
            $this->redirect(array("login/login"));
        }else{
            return $this->renderPartial("first");
        }
这个就是判断是否拥有文件,拥有的话就跳入咱们的登录界面,假如没有就让用户重新安装;

在写这个文件的时候最重要的就是数据库用户,密码,表,以及管理员的账户,密码,这个其实很简单,写入数据库生成运用sql语句就能搞定;

$post=\Yii::$app->request->post();
        $host=$post['dbhost'];
        $name=$post['dbname'];
        $pwd=$post['dbpwd'];
        $db=$post['db'];
        $uname=$post['uname'];
        $upwd=$post['upwd'];

        if (@$link= mysql_connect("$host","$name","$pwd")){
            $db_selected = mysql_select_db("$db", $link);
            if($db_selected){
                $sql="drop database ".$post['db'];
                mysql_query($sql);
            }
            $sql="create database ".$post['db'];
            mysql_query($sql);
            $file=file_get_contents('../sql/we.sql');
            $arr=explode('-- ----------------------------',$file);
            $db_selected = mysql_select_db($post['db'], $link);
            for($i=0;$i<count($arr);$i++){
                if($i%2==0){
                    $a=explode(";",trim($arr[$i]));
                    array_pop($a);
                    foreach($a as $v){
                        mysql_query($v);
                    }
                }
            }
            $str="<?php
					return [
						'class' => 'yii\db\Connection',
						'dsn' => 'mysql:host=".$post['dbhost'].";port=3306;dbname=".$post['db']."',
						'username' => '".$post['dbname']."',
						'password' => '".$post['dbpwd']."',
						'charset' => 'utf8',
						'tablePrefix' => 'we_',   //加入前缀名称we_
					];";
            file_put_contents('../config.php',$str);
            $sql="insert into we_user (uname,upwd) VALUES ('$uname','$upwd')";
            mysql_query($sql);
            mysql_close($link);
            $counter_file       =   '../sql/anzhuang.php';//文件名及路径,在当前目录下新建aa.txt文件
            $fopen                     =   fopen($counter_file,'wb ');//新建文件命令
            fputs($fopen,   'aaaaaa ');//向文件中写入内容;
            fclose($fopen);
            $this->redirect("index.php?r=common/index");
        }else{
            echo "<script>
                        if(alert('数据库账号或密码错误')){
                             location.href='index.php?r=common/index';
                        }else{
                            location.href='index.php?r=commmon/index';
                        }
            </script>";

以上就是我对安装的理解,希望对大家帮助!!!



评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值