@param string $table_name
@param array  $data

@return int $inserted_id
@throws QueryException
961249
public function insert($table_name, array $data) {
            Event::dispatch(EventData::forBefore(Event::BEFORE_INSERT, $table_name, $data), $data);

            $q = $this->config->getSystemIdentifierQuote();
            $fields = [];
            $data_values = "";
            $statement_params = [];
            $null_params = [];

            foreach ($data as $field_name => $value) {
                $fields[] = "\n$q" . $field_name . $q;
                if (strtolower($value) == 'null' || is_null($value)) {
                    $data_values .= 'NULL,';
                    $null_params[ $field_name ] = 'NULL';
                } else {
                    $data_values .= ':' . $field_name . ',';
                    $statement_params[ ':' . $field_name ] = $value;
                }
            }

            $full_param_list = array_merge($statement_params, $null_params);

            $fields = implode(',', $fields);
            $data_values = substr($data_values, 0, -1);
            $sql_query = "INSERT INTO \n$q" . $table_name . "$q ( " . $fields . " )\n VALUES (" . $data_values . ")";
            if ($this->config->db_type === 'pgsql') {
                $sql_query .= "\nRETURNING id;\n";
            }

            try {
                $stmt = $this->db_connection->prepare($sql_query);
                if ($statement_params) {
                    foreach ($statement_params as $k => $v) {
                        $stmt->bindValue($k, $v);
                    }
                }
                $stmt->execute();
            } catch (Exception $ex) {
                Event::dispatch(EventData::forException($ex, $sql_query, $full_param_list));
                throw new QueryException($ex->getMessage(), $ex->getCode(), $ex);
            }

            if ($this->config->db_type === 'pgsql') {
                $insert_id = $stmt->fetchColumn(0);
            } else {
                $insert_id = $this->db_connection->lastInsertId();
            }

            $rows_affected = empty($insert_id) ? 0 : 1;
            Event::dispatch(EventData::forAfter(Event::AFTER_INSERT, $table_name, $full_param_list, $sql_query, $rows_affected, $insert_id));

            return $insert_id;
        }
878930
public function insertBatchStream(string $tableName, array $columns = [], string $format = 'CSV')
    {
        if ($this->getCountPendingQueue() > 0) {
            throw new QueryException('Queue must be empty, before insertBatch, need executeAsync');
        }

        if (! in_array($format, self::SUPPORTED_FORMATS, true)) {
            throw new QueryException('Format not support in insertBatchFiles');
        }

        if (empty($columns)) {
            $sql = 'INSERT INTO ' . $tableName . ' FORMAT ' . $format;
        } else {
            $sql = 'INSERT INTO ' . $tableName . ' ( ' . implode(',', $columns) . ' ) FORMAT ' . $format;
        }

        return $this->transport()->writeStreamData($sql);
    }
9723
public static function insert($table, $data) {
        $insert = Insert::table($table);
        foreach ($data as $field => $value) {
            $insert->set($field, $value);
        }
        return $insert->excuse();
    }
764948
public function delete($table_name, $id) {
            Event::dispatch(EventData::forBefore(Event::BEFORE_DELETE, $table_name, ['id' => $id]));
            $q = $this->config->getSystemIdentifierQuote();

            if (!$id || !$table_name) {
                return false;
            }

            $sql_query = 'DELETE FROM ' . $q . $table_name . $q . ' WHERE ' . $q . 'id' . $q . ' = :delete_id';
            try {
                //Run update query, collect stats
                $stmt = $this->db_connection->prepare($sql_query);
                $stmt->bindValue(':delete_id', $id);
                $stmt->execute();
            } catch (Exception $ex) {
                Event::dispatch(EventData::forException($ex, $sql_query, [':delete_id' => $id]));
                throw new QueryException($ex->getMessage(), $ex->getCode(), $ex);
            }
            $rows_affected = $stmt->rowCount();
            Event::dispatch(EventData::forAfter(Event::AFTER_DELETE, $table_name, [':delete_id' => $id], $sql_query, $rows_affected));

            return $rows_affected;
        }
697163
public function get_table_definition( $table_name ){
		$tabel_definition = @$this->table_definition->tables->{$table_name};
		return ($tabel_definition ? $tabel_definition : false);
	}
115882
public function set($table, $data, $tablePrefix = null)
    {
        is_null($tablePrefix) && $tablePrefix = $this->tablePrefix;
        $tableName = $tablePrefix . $table;
        if (is_array($data)) {
            $s = $this->arrToCondition($data);
            $this->currentQueryIsMaster = true;
            $stmt = $this->prepare("INSERT INTO {$tableName} SET {$s}", $this->wlink);
            $this->execute($stmt);

            $this->setCacheVer($tableName);
            return $this->insertId();
        } else {
            return false;
        }
    }
419996
public function buildInsertSQL($table = null, $data = array())
	{
		$data = $this->parseParams($data);
		if(isAssocArray($data))
		{
			$keys = array_keys($data);
			$valuesKeys = $keys;
			foreach($valuesKeys as $i => $v)
			{
				$valuesKeys[$i] = $this->parseParamName($valuesKeys[$i]);
			}
			return 'insert into ' . $this->parseTable($table) . '(' . implode(',',array_map(array($this,'parseKeyword'),$keys)) . ') values(:' . implode(',:',$valuesKeys) . ')' . $this->parseLock();
		}
		else
		{
			return 'insert into ' . $this->parseTable($table) . ' values(' . substr(str_repeat('?,',count($data)),0,-1) . ')' . $this->parseLock();
		}
	}
272228
public function createUpdateQuery(array $field_data)
    {
        return $this->getQueryFactory()
                    ->createUpdateQuery($this->tableName, $field_data[self::BASE]['id'], $field_data[self::MODIFIED]);
    }
386131
public function insert(Model $m, $data)
    {
        $insert = $m->action('insert');

        // don't set id field at all if it's NULL
        if ($m->id_field && array_key_exists($m->id_field, $data) && $data[$m->id_field] === null) {
            unset($data[$m->id_field]);
        }

        $insert->set($this->typecastSaveRow($m, $data));

        $st = null;

        try {
            $m->hook('beforeInsertQuery', [$insert]);
            $st = $insert->execute();
        } catch (\PDOException $e) {
            throw new Exception([
                'Unable to execute insert query',
                'query'      => $insert->getDebugQuery(false),
                'model'      => $m,
                'conditions' => $m->conditions,
            ], null, $e);
        }

        $m->hook('afterInsertQuery', [$insert, $st]);

        return $m->lastInsertID();
    }
1062748
public static function select($sqlstatement, array $data = [])
    {
        static::verifyConnection();

        if (!preg_match(
            "/^(select\s.+?\sfrom\s.+;?|desc\s.+;?)$/i",
            $sqlstatement
        )) {
            throw new DatabaseException(
                'Syntax Error on the Request',
                E_USER_ERROR
            );
        }

        $pdostatement = static::$adapter
            ->getConnection()
            ->prepare($sqlstatement);

        static::$adapter->bind(
            $pdostatement,
            Sanitize::make($data, true)
        );

        $pdostatement->execute();

        return Sanitize::make($pdostatement->fetchAll());
    }
578062
public function insert($table, array $data)
    {
        $table = $this->getTable($table);
        $field = implode(', ', array_keys($data));

        $placeholder = array();
        foreach ($data as $key => $value) {
            if ($value instanceof \stdClass && isset($value->scalar)) {
                $placeholder[] = $value->scalar;
                unset($data[$key]);
            } else {
                $placeholder[] = '?';
            }
        }
        $placeholder = implode(', ', $placeholder);

        $query = "INSERT INTO $table ($field) VALUES ($placeholder)";
        return $this->executeUpdate($query, array_values($data));
    }
1267783
function insert_search($data)
    {
        if (!$this->ID)
            return false;

        $insert_cols[]   = 'user_id';
        $insert_values[] = (int) $this->ID;
        $insert_cols[]   = $this->db->quote_identifier('type');
        $insert_values[] = (int) $data['type'];
        $insert_cols[]   = $this->db->quote_identifier('name');
        $insert_values[] = $data['name'];
        $insert_cols[]   = $this->db->quote_identifier('data');
        $insert_values[] = serialize($data['data']);

        $sql = "INSERT INTO ".$this->db->table_name('searches', true)
            ." (".join(', ', $insert_cols).")"
            ." VALUES (".join(', ', array_pad(array(), count($insert_values), '?')).")";

        $insert = $this->db->query($sql, $insert_values);

        return $this->db->affected_rows($insert) ? $this->db->insert_id('searches') : false;
    }
1208998
public function haveInDatabase($table, array $data)
    {
        $lastInsertId = $this->_insertInDatabase($table, $data);

        $this->addInsertedRow($table, $data, $lastInsertId);

        return $lastInsertId;
    }
445935
public function insert($table, $data)
    {
        // empty data
        if (empty($data))
            Throw new \ErrorException("SQL Error: Can't insert empty data.");

        // prepare data
        $cols = ($values = array());
        foreach ($data as $column => $value) {
            $cols[] = '`' . $column . '`';
            $values[] = "'" . $this->escape($value) . "'";
        }

        // build query string...
        $query_string = 'INSERT INTO `' . $this->getPrefix() . $table . '` (' . implode(',', $cols) . ') VALUES (' . implode(',', $values) . ')';

        return $this->doQuery($query_string); // ... and execute
    }
1081830
function insert($tableName, $columns, $values = null)
  {
    // Three possibilities
    // string[string] columns, null
    // string[] columns, string[] values
    // string[] columns, string[][] values

    if ($values === null)
    {
      $values = array_values($columns);
      $columns = array_keys($columns);
    }

    $query = "insert into $tableName (`".implode("`,`",$columns)."`) values ";
    if (!is_array($values[0]))
      $query .= "(".$this->quote($values).")";
    else
      $query .= $this->quote($values);
//    {
//      $query .= implode(",",array_map([$this,"quote"],$values));
//    }
//    else
//    {
//      $query .= implode("),(",array_map(function($a){ return implode(",",array_map([$this,"quote"],$a));},$values));
//    }

    $this->q($query);
    return $this->insert_id;
  }
1301427
public function insert(array $data)
    {
        if (isset($data['id'])) {
            if (array_key_exists($data['id'], $this->table->data['data'])) {
                return null;
            }
        } else {
            $data = ['id' => $this->generateId()] + $data;
        }

        $this->table->data['data'][$data['id']] = $data;
        $this->table->save();

        return $data['id'];
    }
976730
protected function _insert(array $data = array())
    {
        if (!is_null($this->_table)) {
            $this->_affectedRows = $this->_db->insert($this->_table, $data);
            if ($this->_affectedRows > 0) {
                $this->id = $this->_db->lastInsertId();
            }
            return $this->_affectedRows;
        }
    }