Run an insert statement against the database.

@param  string $query
@param  array  $bindings

@return bool
@throws InternalServerErrorException
777516
public function insert($query, $bindings = [])
    {
        try {
            $this->statement($query, $bindings);

            return true;
        } catch (\Exception $e) {
            throw new InternalServerErrorException('Insert failed. ' . $e->getMessage());
        }
    }
1098028
protected function execute($sql, $bindings = array())
		{
			$bindings = (array) $bindings;

			// Since expressions are injected into the query as strings, we need to
			// remove them from the array of bindings. After we have removed them,
			// we'll reset the array so there aren't gaps in the keys.
			$bindings = array_values(array_filter($bindings, function($binding) {
				return ! $binding instanceof Expression;
			}));

			$sql = $this->grammar()->shortcut($sql, $bindings);

			$statement = $this->pdo->prepare($sql);

			// Every query is timed so that we can log the executinon time along
			// with the query SQL and array of bindings. This should be make it
			// convenient for the developer to profile performance.
			$time = microtime(true);

			$result = $statement->execute($bindings);

			$time = number_format((microtime(true) - $time) * 1000, 2);

			// Once we have execute the query, we log the SQL, bindings, and
			// execution time in a static array that is accessed by all of
			// the connections used by the application.
			$this->log($sql, $bindings, $time);

			return array($statement, $result);
		}
1100316
protected function getSqlQuery($query, $bindings, $execTime)
    {
        $bindings = $query->bindings;
        $execTime = $query->time;
        $query = $query->sql;
    
        // need to format bindings properly
        foreach ($bindings as $i => $binding) {
            if ($binding instanceof \DateTime) {
                $bindings[$i] = $binding->format('Y-m-d H:i:s');
            } elseif (is_string($binding)) {
                $bindings[$i] = str_replace("'", "\\'", $binding);
            }
        }

        // now we create full SQL query - in case of failure, we log this
        $query = str_replace(['%', '?', "\n"], ['%%', "'%s'", ' '], $query);
        $fullSql = vsprintf($query, $bindings);

        return [$fullSql, $execTime];
    }
661388
public static function executeStmt($stmt, $types, $inserts) {
        self::init();
        try {
            if(!$stmt) {
                throw new DbException('Statement not established');
            } elseif(!$stmt->bind_param($types, ...$inserts)) {
                throw new DbException('Binding error');
            }
            $stmt->execute();
        } catch(DbException $e) {
            self::$_ops->formatError($inserts, $e->getMessage());
        } finally {
            return self::evaluateQuery($stmt);
        }

    }
637749
protected function prepareQuery( $query, array $bindings ) {
		if ( false !== strpos( $query, '%' ) && count( $bindings ) > 0 ) {
			// @codingStandardsIgnoreLine
			$query = $this->wpdb->prepare( $query, $this->prepareBindings( $bindings ) );
		}

		return $query;
	}
318290
public function compileInsert(Builder $query, array $values)
	{
		// Essentially we will force every insert to be treated as a batch insert which
		// simply makes creating the SQL easier for us since we can utilize the same
		// basic routine regardless of an amount of records given to us to insert.
		$table = $this->wrapTable($query->from);

		if ( ! is_array(reset($values)))
		{
			$values = array($values);
		}

		$columns = $this->columnize(array_keys(reset($values)));

		// We need to build a list of parameter place-holders of values that are bound
		// to the query. Each insert should have the exact same amount of parameter
		// bindings so we can just go off the first list of values in this array.
		$parameters = $this->parameterize(reset($values));

		$value = array_fill(0, count($values), "($parameters)");

		$parameters = implode(', ', $value);

		return "insert into $table ($columns) values $parameters";
	}
355332
public function select($query, $bindings = array()) {
        return $this->run($query, $bindings, function(self $me, $query, array $bindings) {
                    if ($me->pretending())
                        return array();
                    // For select statements, we'll simply execute the query and return an array
                    // of the database result set. Each element in the array will be a single
                    // node from the database, and will either be an array or objects.
                     $statement = $me->getBatchQuery($query, $bindings);
                    return $statement->getResultSet();
                    
                    // $statement = $me->getCypherQuery($query, $bindings);
                    // return $statement->getResultSet();

                });
    }
97065
public function statement( $query, $bindings = [] )
	{
		$new_query = $this->bind_params( $query, $bindings, true );

		return $this->unprepared( $new_query );
	}
1138914
public function selectOne($query, $bindings = [])
    {
        $start = $this->getLogTime();

        try {

            $result = $this->wpdb->get_row($this->bindParams($query, $bindings));

            if ($result === false || $this->wpdb->last_error) {
                throw new QueryException($query, $bindings, new \Exception($this->wpdb->last_error));
            }

            return $result;

        } catch (QueryException $e) {
            throw $e;
        } finally {
            $this->logQuery($query, $bindings, $this->getElapsedTime($start));
        }
    }
1309318
public function affectingStatement( $query, $bindings = [] )
	{
		$new_query = $this->bind_params( $query, $bindings, true );

		$result = $this->db->query( $new_query );

		if ( $result === false || $this->db->last_error ) {
			throw new QueryException( $new_query, $bindings, new \Exception( $this->db->last_error ) );
		}

		return intval( $result );
	}
1105172
private function interpolate($query, $bindings)
	{
		$offset = 0;
		$index  = 0;

		foreach (Str::findLiteral('?', $query) as $placeholder)
		{
			$sub     = (is_null($bindings[$index])) ? 'NULL' : $this->quote($bindings[$index]);
			$query   = substr_replace($query, $sub, $placeholder + $offset, 1);
			$offset += (strlen($sub) - 1);
			$index++;
		}

		return $query;
	}
440221
public function insert(KDatabaseQueryInsert $query)
    {
        $context = $this->getContext();
        $context->query = $query;

        //Execute the insert operation
        if ($this->invokeCommand('before.insert', $context) !== false)
        {
            //Check if we have valid data to insert, if not return false
            if ($context->query->values)
            {
                //Execute the query
                $context->result = $this->execute($context->query);
                $context->affected = $this->_affected_rows;

                $this->invokeCommand('after.insert', $context);
            }
            else $context->affected = false;
        }

        return $context->affected;
    }
402095
public function logQuery($query, $bindings, $time = null)
    {
        $this->event(new QueryExecuted($query, $bindings, $time, $this));

        if ($this->loggingQueries) {
            $this->queryLog[] = compact('query', 'bindings', 'time');
        }
    }
750472
public function write($query, array $bindings=[], $returnAffected=null)
    {
        $returnAffected = $returnAffected !== null
                          ? $returnAffected
                          : $this->getOption(static::RETURN_LAST_AFFECTED);

        $this->callBeforeListeners('write',[$query, $bindings]);

        if (!$bindings) {
            $rows = $this->writeUnprepared($query);
            $this->callAfterListeners('write',[$query, $bindings]);
            return $returnAffected ? $rows : null;
        }

        $statement = $this->runPrepared($query, $bindings);

        $this->callAfterListeners('write',[$query, $bindings]);

        return $returnAffected ? $statement->rowCount() : null;
    }
707058
protected function execute(string $query, array $bindings = [])
    {
        $query = N1qlQuery::fromString($query);
        $query->consistency($this->consistency);
        $query->crossBucket($this->crossBucket);
        $query->positionalParams($bindings);
        $result = $this->executeQuery($query);
        $this->metrics = $result->metrics ?? [];

        return $result;
    }
572994
public function insert($query, array $bindings=[], $returnLastInsertId=null)
    {
        $returnLastInsertId = $returnLastInsertId !== null
                              ? $returnLastInsertId
                              : $this->getOption(static::RETURN_LAST_ID);


        $this->callBeforeListeners('insert',[$query, $bindings]);

        $result = $bindings ? $this->runPrepared($query, $bindings)
                            : $this->writeUnprepared($query);

        $this->callBeforeListeners('insert',[$query, $bindings]);

        return $returnLastInsertId ? $this->lastInsertId() : null;
    }
840171
protected function runQueryCallback($query, $bindings, Closure $callback)
    {
        // To execute the statement, we'll simply call the callback, which will actually
        // run the SQL against the PDO connection. Then we can calculate the time it
        // took to execute and log the query SQL, bindings and time in our memory.
        try {
            $result = $callback($query, $bindings);
        }

            // If an exception occurs when attempting to run a query, we'll format the error
            // message to include the bindings with SQL, which will make this exception a
            // lot more helpful to the developer instead of just the database's errors.
        catch (Exception $e) {
            throw new QueryException(
                $query, $bindings, $e
            );
        }

        return $result;
    }