首页 > 解决方案 > laravel DB连接中的数组到字符串转换

问题描述

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

这是一个名为“blessing-skin”的程序的插件配置代码,我试图修改多个数组但它无效。

<?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');
    }
  });
?>

找出数组到字符串转换的原因。

标签: sqlarraysstringlaravel

解决方案


推荐阅读