public function insertMany(string $table, array $maps) : bool
{
if (empty($maps)) {
return false;
}
$first = $maps[0];
foreach ($maps as $map) {
if (\count($map) < 1 || \count($map) !== \count($first)) {
throw new \InvalidArgumentException('Every array in the second argument should have the same number of columns');
}
}
// Begin query string
$queryString = 'INSERT INTO ' . $this->escapeIdentifier($table) . ' (';
// Let's make sure our keys are escaped.
$keys = \array_keys($first);
foreach ($keys as $i => $v) {
$keys[$i] = $this->escapeIdentifier($v);
}
// Now let's append a list of our columns.
$queryString .= \implode(', ', $keys);
// This is the middle piece.
$queryString .= ') VALUES (';
// Now let's concatenate the ? placeholders
$queryString .= \implode(', ', \array_fill(0, \count($first), '?'));
// Necessary to close the open ( above
$queryString .= ');';
// Now let's run a query with the parameters
$stmt = $this->pdo->prepare($queryString);
foreach ($maps as $params) {
$stmt->execute($params);
}
return true;
}