public insert ( string $tableExpression, array $data, array $types = [] ) : integer | ||
$tableExpression | string | The expression of the table to insert data into, quoted or unquoted. |
$data | array | An associative array containing column-value pairs. |
$types | array | Types of the inserted data. |
return | integer | The number of affected rows. |
public function insert($tableExpression, array $data, array $types = array())
{
if (empty($data)) {
return $this->executeUpdate('INSERT INTO ' . $tableExpression . ' ()' . ' VALUES ()');
}
return $this->executeUpdate('INSERT INTO ' . $tableExpression . ' (' . implode(', ', array_keys($data)) . ')' . ' VALUES (' . implode(', ', array_fill(0, count($data), '?')) . ')', array_values($data), is_string(key($types)) ? $this->extractTypeValues($data, $types) : $types);
}
/** * @param string $tableName * @param array $rows */ protected function insertTableRows($tableName, array $rows) { foreach ($rows as $rowKey => $values) { $this->connection->insert($tableName, $this->parser->parse($values)); $this->parser->addReference($rowKey, $this->connection->lastInsertId()); } }