public function insert($table, $datas)
{
$lastId = array();
if (!isset($datas[0])) {
$datas = array($datas);
}
foreach ($datas as $data) {
$values = array();
$columns = array();
foreach ($data as $key => $value) {
array_push($columns, $this->column_quote($key));
switch (gettype($value)) {
case 'NULL':
$values[] = 'NULL';
break;
case 'array':
preg_match("/\\(JSON\\)\\s*([\\w]+)/i", $key, $column_match);
$values[] = isset($column_match[0]) ? $this->quote(json_encode($value)) : $this->quote(serialize($value));
break;
case 'boolean':
$values[] = $value ? '1' : '0';
break;
case 'integer':
case 'double':
case 'string':
$values[] = $this->fn_quote($key, $value);
break;
}
}
$this->exec('INSERT INTO "' . $table . '" (' . implode(', ', $columns) . ') VALUES (' . implode($values, ', ') . ')');
$lastId[] = $this->pdo->lastInsertId();
}
return count($lastId) > 1 ? $lastId : $lastId[0];
}