lgy 6 年之前
父节点
当前提交
f63de8a41d
共有 1 个文件被更改,包括 83 次插入0 次删除
  1. 83 0
      application/admin/command/Upgrade.php

+ 83 - 0
application/admin/command/Upgrade.php

@@ -0,0 +1,83 @@
+<?php
+namespace app\admin\command;
+
+use think\console\Command;
+use think\console\Input;
+use think\console\Output;
+
+class Upgrade extends Command
+{
+    protected function configure()
+    {
+        $this->setName('upgrade')->setDescription('Version upgrades');
+    }
+
+    protected function execute(Input $input, Output $output)
+    {
+//        'hostname'        => '47.104.6.21',
+    //'hostname'        => '47.104.4.5',
+//        'database'        => 'pacsonline',
+    //'database'        => 'db_remote_diag',
+        // 用户名
+//        'username'        => 'pacs',
+    // 密码
+//    'password'        => 'ZSKK@2017~!@#',
+        $username = 'pacs';
+        $password = 'ZSKK@2017~!@#';
+        $link = @mysqli_connect('localhost', 'root', '');
+        if(!mysqli_select_db($link, 'db_remote_diag')){
+            echo '数据库选择失败';
+            exit;
+        }
+        $sql = "select * from version";
+        $info = mysqli_query($link, $sql);
+
+        $link1 = @mysqli_connect('47.104.4.5', $username, $password);
+        if(!mysqli_select_db($link1, 'db_remote_diag')){
+            echo '数据库选择失败';
+            exit;
+        }
+        $sql = "select * from version";
+        $info1 = mysqli_query($link1, $sql);
+        if($info1['version'] > $info['version']){
+            $num = $info['version'];
+            for($num;$num<=$info1['version'];$num++){
+                $return =$this->upgrade_version($num);
+                mysqli_set_charset($link, 'utf8');
+                $res = mysqli_query($link, $return);
+                if($res){
+                    $output->writeln("成功");
+                }else{
+                    $output->writeln("失败");
+                }
+            }
+        }else{
+            return '数据错误';
+        }
+
+
+
+        // mysql_query($sql,$con);
+        // ALTER TABLE people ADD COLUMN name VARCHAR(100) DEFAULT NULL COMMENT '姓名'   修改表 people  增加字段 name    长度100  默认为null
+        // ALTER TABLE `t_check_store` DROP contract_status;
+        // alter table student change physics physisc char(10) not null;
+        mysqli_close($link);
+        $output->writeln("2");
+        $output->writeln("3");
+    }
+
+    public function upgrade_version($version){
+        switch($version){
+            case 1:
+                 // 建表
+                    $sql = "CREATE TABLE Persons
+                    (
+                    FirstName varchar(15),=
+                    LastName varchar(15),
+                    Age int
+                    )";
+                return sql;
+                break;
+        }
+    }
+}