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->name = 'test name';
$qt->machine_name = 'test machine name';
$qt->settings = array('setting1'=>value1, 'setting2'=>value2);
$query = \Drupal::database()->insert('my_custom_table');
$query->fields([
'machine_name',
'name',
'settings',
]);
$query->values([
$ob->machine_name,
$ob->name,
$ob->settings,
]);
$query->execute();
If I am giving values like below it is working. Please help me whats wrong with above code.
$query->values([
'test',
'ttt',
'dfs',
]);
$query->execute();
['key' => 'value']
format