正在显示
1 个修改的文件
包含
2 行增加
和
3 行删除
| @@ -104,17 +104,16 @@ class Demo extends Command | @@ -104,17 +104,16 @@ class Demo extends Command | ||
| 104 | public function handle(){ | 104 | public function handle(){ |
| 105 | return $this->initTable(1380,1862); | 105 | return $this->initTable(1380,1862); |
| 106 | } | 106 | } |
| 107 | - | 107 | + |
| 108 | public function initTable($project_id, $news_project_id) | 108 | public function initTable($project_id, $news_project_id) |
| 109 | { | 109 | { |
| 110 | config(['database.connections.custom_tmp_mysql_copy.database' => 'gl_data_' . $project_id]); | 110 | config(['database.connections.custom_tmp_mysql_copy.database' => 'gl_data_' . $project_id]); |
| 111 | $database_name = DB::connection('custom_tmp_mysql_copy')->getDatabaseName(); | 111 | $database_name = DB::connection('custom_tmp_mysql_copy')->getDatabaseName(); |
| 112 | $tables = Schema::connection('custom_tmp_mysql_copy')->getAllTables(); | 112 | $tables = Schema::connection('custom_tmp_mysql_copy')->getAllTables(); |
| 113 | $tables = array_column($tables, 'Tables_in_' . $database_name); | 113 | $tables = array_column($tables, 'Tables_in_' . $database_name); |
| 114 | - | ||
| 115 | foreach ($tables as $table) { | 114 | foreach ($tables as $table) { |
| 115 | + config(['database.connections.custom_mysql.database' => 'gl_data_' . $news_project_id]); | ||
| 116 | $has_table = Schema::connection('custom_mysql')->hasTable($table); | 116 | $has_table = Schema::connection('custom_mysql')->hasTable($table); |
| 117 | - | ||
| 118 | if (!$has_table) { | 117 | if (!$has_table) { |
| 119 | $sql = DB::connection('custom_tmp_mysql_copy')->select("SHOW CREATE TABLE {$table}"); | 118 | $sql = DB::connection('custom_tmp_mysql_copy')->select("SHOW CREATE TABLE {$table}"); |
| 120 | DB::connection('custom_mysql')->statement(array_values((array)$sql[0])[0]); // 修正此处的sql语句获取方式 | 119 | DB::connection('custom_mysql')->statement(array_values((array)$sql[0])[0]); // 修正此处的sql语句获取方式 |
-
请 注册 或 登录 后发表评论