Laravel DB连接中的数组到字符串的转换

时间:2019-05-25 07:41:59

标签: sql arrays string laravel

我正在尝试解决导致数组转换为字符串的有问题的代码,但我找不到问题。

这是一个名为“祝福皮肤”程序的插件的配置代码,我尝试修改多个数组,但是无效。

<?php
  $targetDbConfigForm = Option::form('connection', 'database setting', function ($form) {
    $form->text('forum_db_config[host]',     'TargetSqlAddress')->hint('There may be a delay in interfacing between database hosts, so please be aware.');
    $form->text('forum_db_config[port]',     'port');
    $form->text('forum_db_config[database]', 'database');
    $form->text('forum_db_config[username]', 'username');
    $form->text('forum_db_config[password]', 'password');
    $form->text('forum_db_config[table]',    'table');
    $form->select('forum_duplicated_prefer', 'duplicated prefer')
      ->option('remote', 'Use remote data')
      ->option('local',  'Use local data')
      ->description('After this selection, if the user data (such as the same user name and different username and password) conflicts, the option you choose will be used, and the user data of the other party will be overwritten.');
  })->handle()->always(function ($form) {
    $config = request('forum_db_config');
    if ($config) {
      option(['forum_db_config' => serialize($config)]);
    } else {
      $config = @unserialize(option('forum_db_config'));
    }
    config(['database.connections.remote' => array_merge(
      forum_get_default_db_config(), (array) $config
    )]);
    try {
      DB::connection('remote')->getPdo();
      if (Schema::connection('remote')->hasTable($config['table'])) {
        $form->addMessage('Connected', 'success');
      } else {
        $form->addMessage("Connected to databse,but table [{$config['table']}] not found.", 'warning');
      }
    } catch (Exception $e) {
      $form->addMessage('Cannot connect to MySQL server. <br>Error info: '.$e->getMessage(), 'danger');
    }
  });
?>

查找将数组转换为字符串的原因。

0 个答案:

没有答案