protected function _insert(&$document)
{
$table = $this->name;
$document["_id"] = uniqid() . 'doc' . rand();
$data = array("document" => json_encode($document, JSON_NUMERIC_CHECK | JSON_UNESCAPED_UNICODE));
$fields = array();
$values = array();
foreach ($data as $col => $value) {
$fields[] = "`{$col}`";
$values[] = is_null($value) ? 'NULL' : $this->database->connection->quote($value);
}
$fields = implode(',', $fields);
$values = implode(',', $values);
$sql = "INSERT INTO {$table} ({$fields}) VALUES ({$values})";
$res = $this->database->connection->exec($sql);
if ($res) {
return $this->database->connection->lastInsertId();
} else {
trigger_error('SQL Error: ' . implode(', ', $this->database->connection->errorInfo()) . ":\n" . $sql);
return false;
}
}