Placeholders must have a trailing [] if they are to be expanded with an array of values In Drupal 8 I am trying to insert some data in my custom table. While executing query I am getting error:


  InvalidArgumentException: Placeholders must have a trailing [] if they are to be expanded with an array of values. in Drupal\Core\Database\Connection->expandArguments() 


Please find my code below:

$qt = new \stdClass();
$qt-&gt;name = 'test name';
$qt-&gt;machine_name = 'test machine name';
$qt-&gt;settings = array('setting1'=&gt;value1, 'setting2'=&gt;value2);

$query = \Drupal::database()-&gt;insert('my_custom_table');
$query-&gt;fields([
  'machine_name',
  'name',
  'settings',
]);
$query-&gt;values([
  $ob-&gt;machine_name,
  $ob-&gt;name,
  $ob-&gt;settings,
]);
$query-&gt;execute();


If I am giving values like below it is working. Please help me whats wrong with above code.

$query-&gt;values([
  'test',
  'ttt',
  'dfs',
]);
$query-&gt;execute();
That issue got resolved. It was regarding passing array in to the db. Added serialise function resloved the issue.

$query-&gt;values([
$ob-&gt;machine_name,
$ob-&gt;name,
serialize($ob-&gt;settings),
]);
$query-&gt;execute();