Commit 5dd0adfe authored by Guilherme Blanco's avatar Guilherme Blanco

Merge pull request #314 from deeky666/microoptimize-connection-insert

Remove unnecessary code from Connection::insert
parents 38f67937 5b86fad8
...@@ -533,22 +533,13 @@ class Connection implements DriverConnection ...@@ -533,22 +533,13 @@ class Connection implements DriverConnection
{ {
$this->connect(); $this->connect();
// column names are specified as array keys
$cols = array();
$placeholders = array();
foreach ($data as $columnName => $value) {
$cols[] = $columnName;
$placeholders[] = '?';
}
if ( ! is_int(key($types))) { if ( ! is_int(key($types))) {
$types = $this->extractTypeValues($data, $types); $types = $this->extractTypeValues($data, $types);
} }
$query = 'INSERT INTO ' . $tableName $query = 'INSERT INTO ' . $tableName
. ' (' . implode(', ', $cols) . ')' . ' (' . implode(', ', array_keys($data)) . ')'
. ' VALUES (' . implode(', ', $placeholders) . ')'; . ' VALUES (' . implode(', ', array_fill(0, count($data), '?')) . ')';
return $this->executeUpdate($query, array_values($data), $types); return $this->executeUpdate($query, array_values($data), $types);
} }
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment