Upgrade.php 2.5 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283
  1. <?php
  2. namespace app\admin\command;
  3. use think\console\Command;
  4. use think\console\Input;
  5. use think\console\Output;
  6. class Upgrade extends Command
  7. {
  8. protected function configure()
  9. {
  10. $this->setName('upgrade')->setDescription('Version upgrades');
  11. }
  12. protected function execute(Input $input, Output $output)
  13. {
  14. // 'hostname' => '47.104.6.21',
  15. //'hostname' => '47.104.4.5',
  16. // 'database' => 'pacsonline',
  17. //'database' => 'db_remote_diag',
  18. // 用户名
  19. // 'username' => 'pacs',
  20. // 密码
  21. // 'password' => 'ZSKK@2017~!@#',
  22. $username = 'pacs';
  23. $password = 'ZSKK@2017~!@#';
  24. $link = @mysqli_connect('localhost', 'root', '');
  25. if(!mysqli_select_db($link, 'db_remote_diag')){
  26. echo '数据库选择失败';
  27. exit;
  28. }
  29. $sql = "select * from version";
  30. $info = mysqli_query($link, $sql);
  31. $link1 = @mysqli_connect('47.104.4.5', $username, $password);
  32. if(!mysqli_select_db($link1, 'db_remote_diag')){
  33. echo '数据库选择失败';
  34. exit;
  35. }
  36. $sql = "select * from version";
  37. $info1 = mysqli_query($link1, $sql);
  38. if($info1['version'] > $info['version']){
  39. $num = $info['version'];
  40. for($num;$num<=$info1['version'];$num++){
  41. $return =$this->upgrade_version($num);
  42. mysqli_set_charset($link, 'utf8');
  43. $res = mysqli_query($link, $return);
  44. if($res){
  45. $output->writeln("成功");
  46. }else{
  47. $output->writeln("失败");
  48. }
  49. }
  50. }else{
  51. return '数据错误';
  52. }
  53. // mysql_query($sql,$con);
  54. // ALTER TABLE people ADD COLUMN name VARCHAR(100) DEFAULT NULL COMMENT '姓名' 修改表 people 增加字段 name 长度100 默认为null
  55. // ALTER TABLE `t_check_store` DROP contract_status;
  56. // alter table student change physics physisc char(10) not null;
  57. mysqli_close($link);
  58. $output->writeln("2");
  59. $output->writeln("3");
  60. }
  61. public function upgrade_version($version){
  62. switch($version){
  63. case 1:
  64. // 建表
  65. $sql = "CREATE TABLE Persons
  66. (
  67. FirstName varchar(15),=
  68. LastName varchar(15),
  69. Age int
  70. )";
  71. return sql;
  72. break;
  73. }
  74. }
  75. }