Exports insert SQL.

@param  array  $data
@return string
770529
protected function exportInsert(array $data)
    {
        $insertSql = '';
        $insert = new Insert(self::TABLE_NAME);
        foreach ($data as $id => $value) {
            $insertSql .= @$insert
                ->values(array('id' => $id, 'value' => $value))
                ->getSqlString($this->getPlatform()).';'.PHP_EOL;
        }

        return $insertSql;
    }
271500
public function getList(array $data = array())
    {
        $sql = 'SELECT b.*, u.name AS user_name';

        if (!empty($data['count'])) {
            $sql = 'SELECT COUNT(b.backup_id)';
        }

        $sql .= ' FROM backup b
                  LEFT JOIN user u ON(b.user_id = u.user_id)
                  WHERE b.backup_id > 0';

        $where = array();

        if (isset($data['user_id'])) {
            $sql .= ' AND b.user_id = ?';
            $where[] = $data['user_id'];
        }

        if (isset($data['id'])) {
            $sql .= ' AND b.id = ?';
            $where[] = $data['id'];
        }

        if (isset($data['version'])) {
            $sql .= ' AND b.version = ?';
            $where[] = $data['version'];
        }

        if (isset($data['name'])) {
            $sql .= ' AND b.name LIKE ?';
            $where[] = "%{$data['name']}%";
        }

        $allowed_order = array('asc', 'desc');
        $allowed_sort = array('name', 'user_id', 'version',
            'id', 'backup_id', 'type', 'created');

        if (isset($data['sort'])
            && in_array($data['sort'], $allowed_sort)
            && isset($data['order'])
            && in_array($data['order'], $allowed_order)
        ) {
            $sql .= " ORDER BY b.{$data['sort']} {$data['order']}";
        } else {
            $sql .= ' ORDER BY b.created DESC';
        }

        if (!empty($data['limit'])) {
            $sql .= ' LIMIT ' . implode(',', array_map('intval', $data['limit']));
        }

        if (!empty($data['count'])) {
            return (int) $this->db->fetchColumn($sql, $where);
        }

        $results = $this->db->fetchAll($sql, $where, array('index' => 'backup_id'));
        $this->hook->attach('module.backup.list', $results, $this);
        return $results;
    }
564480
public function insertBatch(string $table, array $data=[]): array
	{
		// If greater than version 3.7.11, supports the same syntax as
		// MySQL and Postgres
		if (version_compare($this->getAttribute(PDO::ATTR_SERVER_VERSION), '3.7.11', '>='))
		{
			return parent::insertBatch($table, $data);
		}

		// --------------------------------------------------------------------------
		// Otherwise, do a union query as an analogue to a 'proper' batch insert
		// --------------------------------------------------------------------------

		// Each member of the data array needs to be an array
		if ( ! \is_array(current($data)))
		{
			return NULL;
		}

		// Start the block of sql statements
		$table = $this->quoteTable($table);
		$sql = "INSERT INTO {$table} \n";

		// Create a key-value mapping for each field
		$first = array_shift($data);
		$cols = [];
		foreach($first as $colname => $datum)
		{
			$cols[] = $this->_quote($datum) . ' AS ' . $this->quoteIdent($colname);
		}
		$sql .= 'SELECT ' . implode(', ', $cols) . "\n";

		foreach($data as $union)
		{
			$vals = array_map([$this, 'quote'], $union);
			$sql .= 'UNION SELECT ' . implode(',', $vals) . "\n";
		}

		return [$sql, NULL];
	}
882338
public function create_sql_insert_string(array $data) {
		#$retval = "";
		if(is_array($data) && count($data)) {
			$fields = "";
			$values = "";
			foreach($data as $k=>$v) {
				$fields = ToolBox::create_list($fields, $k, ", ");
				$values = ToolBox::create_list($values, ':'. $k, ", ");
			}
			if(strlen($fields) && strlen($values)) {
				$retval = ' ('. $fields .') VALUES ('. $values .')';
			}
			else {
				throw new Exception(__METHOD__ .": no fields (". $fields .") or values (". $values .") created... ". $this->gfObj->debug_print($data,0));
			}
		}
		else {
			throw new Exception(__METHOD__ .": unable to create insert string, no fields given");
		}
		
		return($retval);
	}
1260791
protected function insert(array $data = array())
    {
        $fields = array();
        $values = array();
        
        foreach ($data as $field => $value) {
            $fields[] = $field;
            $values[] = '?';
        }
        
        $sql = "INSERT INTO $this->_table " 
                . "(" . implode(', ', $fields) . ")"
                . "VALUES (" . implode(', ', $values) . ")";
                
        $pdos = $this->_pdo->prepare($sql);
        
        $pdos->execute(array_values($data));
        
        return $pdos->statement()->rowCount();
    }
399398
public function insert($data)
	{
		//var_dump($data);
		unset($this->_error);
		if(is_array($data))
		{
			$fields = '';
			$values = '';
			reset($data);
			for($counter = 0, $maxIndex = count($data), $valid = true; $counter < $maxIndex && $valid == true; $counter ++)
			{
				$elementKey = key($data);
				$elementKey = $this->_db->escape($elementKey);
				$valid = in_array($elementKey, $this->_fields);
				if($valid == true)
				{
                    $element = $data[$elementKey];
                    $element = $this->_db->escape($element);
					if(is_object($element) == true)
					{
						$valid = false;
						$this->_error = 'field: '.$elementKey.'is an object (this method just accept strings)';
					}
					else
					{
						if(is_numeric($element) == false)
							$values .= '\''.$element.'\'';
						else
							$values .= $element;
						$fields .= $elementKey;
						if(($counter + 1) < $maxIndex)
						{
							$fields .= ',';
							$values .= ',';
						}
						next($data);
					}
				}
				else
				{
					$this->_error = 'field: '.$elementKey.' is not defined in '.$this->_tableName;
				}
			}
			if($valid == true)
			{
				$this->_query = 'INSERT INTO '.$this->_tableName.'('.$fields.') VALUES('.$values.')';
				if($this->_db->execute($this->_query) !== false)
				{
					return $this->_db->insertId();
				}
				else
				{
					$this->_error = $this->_db->errorStr();
				}
			}
		}
		return false;
	}
1101996
public function insert(array $data) {
        $this->notifyObservers('beforeInsert', array($this, &$data));
        $pkData = parent::insert($data);
        $this->notifyObservers('afterInsert', array($this, $data, $pkData));
        return $pkData;
    }
727304
public function generate(array $data): string
    {
        $connectionPool = GeneralUtility::makeInstance(ConnectionPool::class);
        $connection = $connectionPool->getConnectionForTable('tx_styleguide_inline_expandsingle_child');
        $childRowsToCreate = 3;
        for ($i = 0; $i < $childRowsToCreate; $i++) {
            // Insert an empty row again to have the uid already. This is useful for
            // possible further inline that may be attached to this child.
            $childFieldValues = [
                'pid' => $data['fieldValues']['pid'],
                'parentid' => $data['fieldValues']['uid'],
                'parenttable' => $data['tableName'],
            ];
            $connection->insert(
                'tx_styleguide_inline_expandsingle_child',
                $childFieldValues
            );
            $childFieldValues['uid'] = $connection->lastInsertId('tx_styleguide_inline_expandsingle_child');
            $recordData = GeneralUtility::makeInstance(RecordData::class);
            $childFieldValues = $recordData->generate('tx_styleguide_inline_expandsingle_child', $childFieldValues);
            $connection->update(
                'tx_styleguide_inline_expandsingle_child',
                $childFieldValues,
                [ 'uid' => $childFieldValues['uid'] ]
            );
        }
        return (string)$childRowsToCreate;
    }
130656
protected function _insert(array $data)
    {
        $data = $this->_setData($data);
        $sql = Sql::createSql($this->getAdapter())->insert($this->getTableName());
        $event = new Save([
            'action' => Save::INSERT,
            'data' => $data,
            'abort' => false
        ]);
        $this->getEventManager()->trigger(Save::BEFORE_SAVE, $this, $event);
        if ($event->abort) {
            return false;
        }
        $result = $sql->set($event->data)->execute();

        if ($result > 0) {
            $pmk = $this->getPrimaryKey();
            $this->$pmk = $this->getAdapter()->getLastInsertId();
            $this->getEventManager()->trigger(Save::AFTER_SAVE, $this, $event);
        }
        return $result > 0;
    }
1199415
public function replace(array $data) {
        $addFields = implode('`,`', array_keys($data));
        return $this->command()
            ->insertOrReplace("`{$addFields}`", Str::repeat('?', $data),
                array_values($data));
    }
1143745
protected function insert($data)
    {
        try {

            if ($this->creationTouch) {
                $data[$this->creationTouchName] = date('Y-m-d H:i:s');
            }

            $this->db->insert($this->table, $this->fromArray($data));

            $id = $this->db->lastInsertId($this->sequence ? $this->sequence : $this->primaryKey);

        } catch (\Exception $e) {
            throw $e;
        }

        return $id;
    }
873476
public function insert(array $data, $table = null)
    {
        $table = ($table) ?: $this->getTable();
        $sql = $this->getSql();
        $insert = $sql->insert($table);

        $insert->values($data);

        $statement = $sql->prepareStatementForSqlObject($insert);
        $result = $statement->execute();

        return $result->getGeneratedValue();
    }
143355
public function insert($table, $data = [])
    {
        // check if table name not empty
        if (!empty($table)) {
            // and array data not empty
            if (count($data) > 0 && is_array($data)) {
                // get array insert data in temp array
                $tmp = [];
                foreach ($data as $f => $v) {
                    $tmp[] = ":s_$f";
                }
                // make name space param for pdo insert statement
                $sNameSpaceParam = implode(',', $tmp);
                // unset temp var
                unset($tmp);
                // get insert fields name
                $sFields = implode(',', array_keys($data));
                // set pdo insert statement in class property
                $this->sql = "INSERT INTO `$table` ($sFields) VALUES ($sNameSpaceParam);";
                // pdo prepare statement
                $this->STH = $this->prepare($this->sql);
                // set class where property with array data
                $this->data = $data;
                // bind pdo param
                $this->_bindPdoNameSpace($data);
                // use try catch block to get pdo error
                try {
                    // execute pdo statement
                    if ($this->STH->execute()) {
                        // set class property with last insert id
                        $this->lastId = $this->lastInsertId();
                        // close pdo
                        $this->STH->closeCursor();
                        // return this object
                        return $this;
                    } else {
                        self::error($this->STH->errorInfo());
                    }
                } catch (\PDOException $e) {
                    // get pdo error and pass on error method
                    self::error($e->getMessage() . ': ' . __LINE__);
                }
            } else {
                self::error('Data not in valid format..');
            }
        } else {
            self::error('Table name not found..');
        }
    }
834688
public function insert(SQLStatement $insert): string
    {
        $columns = $this->handleColumns($insert->getColumns());

        $sql = 'INSERT INTO ';
        $sql .= $this->handleTables($insert->getTables());
        $sql .= ($columns === '*') ? '' : ' (' . $columns . ')';
        $sql .= $this->handleInsertValues($insert->getValues());

        return $sql;
    }
261923
private function asData(array $data)
    {
        foreach ($data as $key => $value) {
            if ($value instanceof RawSqlFragmentInterface) {
                $data[$key] = $value->getFragment();
            } elseif ($value instanceof RawBindingInterface) {
                $data[$key] = $value->getTarget();
            } else {
                $placeholder = $this->getUniqPlaceholder();

                $data[$key] = $placeholder;
                $this->bind($placeholder, $value);
            }
        }

        return $data;
    }
981372
public function insert($data = null)
    {
        $currentIndex = $this->getFieldValue($this->getIndex());
        $fields = $this->getFields();
        $sql1 = '';
        $sql2 = '';
        $args = array();
        foreach ($fields as $field) {
            // if($this->getFieldValue($field, $data) !== NULL)
            if (in_array($field, $this->created_at_fileds)) {
                $this->{$field} = now();
            }
            $value = $this->getFieldValue($field, $data);
            $args[$field] = $value;
            $sql1 .= "`$field`, ";
            $sql2 .= ":$field, ";
        }
        if (!empty($sql1)) {
            $sql1 = substr($sql1, 0, -2);
            $sql2 = substr($sql2, 0, -2);
            if($currentIndex) {
                $this->db->removeCache($this->getCacheId($currentIndex));
            }
            return $this->db->insert('INSERT INTO `'.$this->table_name.'` ('.$sql1.') VALUES ('.$sql2.')', $args);
        }
        return false;
    }
546122
static public function add($data)
    {
        try {
            $model = new static;
            $attributes = array_flip($model->attributes);
            $data = array_filter($data, function ($data) use ($attributes) {
                return isset($attributes[$data]);
            }, ARRAY_FILTER_USE_KEY);
            $sql = 'INSERT INTO '.$model->table.' (';
            foreach ($data as $column => $value) {
                $sql .= '`'.$column.'`, ';
            }
            $sql = trim($sql, ', ');
            $sql .= ') VALUES (';
            foreach ($data as $column => $value) {
                $sql .= ':'.$column.', ';
            }
            $sql = trim($sql, ', ');
            $sql .= ')';
            $statement = $model->connect->prepare($sql);
            foreach ($data as $column => $value) {
                $statement->bindValue(':'.$column, $value);
            }
            try {
                $statement->execute();
                return $model->connect->lastInsertId();
            } catch(\PDOExecption $e) {
                $model->connect->rollback();
                return "Error" . $e->getMessage();
            }
        } catch( \PDOExecption $e ) {
            return "Error" . $e->getMessage();
        }
    }