prepareValues

Prepare parameters to be sent.

@param  string   $sql
@param  array    $values
@return array    $prepared_values
173813
protected function prepareValues($sql, array $values)
    {
        if ($this->converters === null) {
            $this->prepareConverters($sql);
        }

        foreach ($values as $index => $value) {
            if (isset($this->converters[$index])) {
                $values[$index] = call_user_func($this->converters[$index], $value);
            }
        }

        return $values;
    }
879919
public function prepare(string $sql): ?\PDOStatement {
        $statement = $this->getConnection()->prepare($sql);
        if ($statement === false) {
            return null;
        }
        $this->statement = $statement;
        return $statement;
    }
837242
public function prepare(string $sql, $standalone = false)
    {
        try {
            $stmt = $this->dbh->prepare($sql);
            if ($standalone) {
                return $stmt;
            } else {
                $this->stmt = $stmt;
            }
            return $this;
        } catch (\PDOException $e) {
            die("Error: " . $e->getMessage());
        }
    }
496044
public function process($sql)
    {
        $bindFormatted=[];
        $bindRaw=[];
        foreach ($this->bindings as $key => $value) {
            if (is_array($value)) {
                $valueSet = implode(', ', $value);

                $values = array_map(
                    function ($value) {
                        return ValueFormatter::formatValue($value);
                    },
                    $value
                );

                $formattedParameter = implode(',', $values);
            } else {
                $valueSet           = $value;
                $formattedParameter = ValueFormatter::formatValue($value);
            }

            if ($formattedParameter !== null) {
                $bindFormatted[$key]=$formattedParameter;
            }

            if ($valueSet !== null) {
                $bindRaw[$key]=$valueSet;
            }
        }

        for ($loop=0;$loop<2;$loop++)
        {
            // dipping in binds
            // example ['A' => '{B}' , 'B'=>':C','C'=>123]
            $sql=$this->compile_binds($sql,$bindRaw,'#{([\w+]+)}#');
        }
        $sql=$this->compile_binds($sql,$bindFormatted,'#:([\w+]+)#');

        return $sql;
    }
1359238
public function prepareAndExecuteSql($sql, $binds = [])
    {
        $prepare = $this->prepareSQL($sql, $binds);

        return $this->executePrepared($prepare);
    }
1253117
public function prepareUpdate($table, array $values) {

        // Initialize the SET.
        $set = [];
        foreach ($values as $k => $v) {
            $set[] = "`" . $k . "` = " . $v;
        }

        // Initialize the query.
        $query = [];

        $query[] = "UPDATE ";
        $query[] = $table;
        $query[] = " SET ";
        $query[] = implode(", ", $set);

        // Return the query.
        return implode("", $query);
    }
849114
private function prepareAndExecuteQuery($sql, $arguments)
    {
        if ($this->log || $this->on_log_query) {
            $microtime = microtime(true);

            $prepared_sql = empty($arguments) ?
                $sql :
                call_user_func_array([&$this, 'prepare'], array_merge([$sql], $arguments));

            $result = $this->link->query($prepared_sql);

            $execution_time = rtrim(number_format(microtime(true) - $microtime, 6, '.', ''), '0');

            if ($this->log) {
                if ($result === false) {
                    $this->log->error('Query error {error_message}', [
                        'error_message' => $this->link->error,
                        'error_code' => $this->link->errno,
                        'sql' => $prepared_sql,
                        'exec_time' => $execution_time,
                    ]);
                } else {
                    $this->log->debug('Query {sql} executed in {exec_time}s', [
                        'sql' => $prepared_sql,
                        'exec_time' => $execution_time,
                    ]);
                }
            }

            if ($this->on_log_query) {
                call_user_func($this->on_log_query, $prepared_sql, $execution_time);
            }

            return $result;
        } else {
            return empty($arguments) ?
                $this->link->query($sql) :
                $this->link->query(call_user_func_array([&$this, 'prepare'], array_merge([$sql], $arguments)));
        }
    }
1273079
public function execute($sql, $params = null)
    {
        $stmt = $this->_pdo->prepare($sql);

        if (is_array($params)) {
            foreach ($params as $token => $value) {
                $stmt->bindValue($token, $value);
            }
        }

        try {
            $stmt->execute();
        } catch (PDOException $exception) {
            $this->_database->error('execute', $exception);
        }

        return $stmt;
    }
11572
protected function prepareArrayPlaceholders($sql)
    {
        if (!count($this->arrays)) {
            return $sql;
        }
        foreach ($this->arrays as $placeholder => $array) {
            if (strpos($sql, $placeholder) === false) {
                continue;
            }

            $placeholders = [];
            $cnt = count($array);
            for ($i = 0; $i < $cnt; $i++) {
                $placeholders[] = $placeholder . $i;
            }
            $sql = str_replace($placeholder, '(' . implode(', ', $placeholders) . ')', $sql);
        }

        return $sql;
    }
1051170
public function prepare($sql, $options = null) {
        try {
            Log::getHandler()->debug($sql);
            $stmt = parent::prepare($sql, $options);
        } catch (PDOException $ex) {
            Log::getHandler()->error($ex->getMessage());
        }
        return $stmt;
    }
362701
public function prepare($sql, $driverOptions = [])
    {
        $this->placeholders = $this->types = [];
        $sql = preg_replace_callback(static::PLACEHOLDER_REGEX, function ($matches) {
            $name = $matches[2];
            if (!isset($this->types[$name])) {
                $this->types[$name] = static::$typeMap[$matches[1]];
            }
            $this->placeholders[] = $name;

            return '?';
        }, $sql);

        return parent::prepare($sql, $driverOptions);
    }
571054
public function prepareInsert($table, array $values) {

        // Initialize the query.
        $query = [];

        $query[] = "INSERT INTO ";
        $query[] = $table;
        $query[] = " (`";
        $query[] = implode("`, `", array_keys($values));
        $query[] = "`) VALUES (";
        $query[] = implode(", ", array_values($values));
        $query[] = ")";

        // Return the query.
        return implode("", $query);
    }
273015
public function update(array $values): array
	{
		$sql  = $this->query->getPrefix();
		$sql .= 'UPDATE ';
		$sql .= $this->escapeTable($this->query->getTable());
		$sql .= ' SET ';
		$sql .= $this->updateColumns($values);
		$sql .= $this->wheres($this->query->getWheres());

		return ['sql' => $sql, 'params' => $this->params];
	}
760123
protected function _prep_query($sql)
	{
		// mysql_affected_rows() returns 0 for "DELETE FROM TABLE" queries. This hack
		// modifies the query so that it a proper number of affected rows is returned.
		if ($this->delete_hack === TRUE && preg_match('/^\s*DELETE\s+FROM\s+(\S+)\s*$/i', $sql))
		{
			return trim($sql).' WHERE 1=1';
		}

		return $sql;
	}
811619
public static function preparedQuery($sql) {
        self::init();
        if(!empty($exclusions = self::$_ops->getExclusions())) {
            $prepared = self::prepareStmt($sql);
            $inserts = [];
            $types = '';
            foreach($exclusions as $i => $substitute) {
                $types .= $substitute['type'];
                $inserts[] = $substitute['value'];
            }
            return self::executeStmt($prepared, $types, $inserts);
        } else {
            return self::query($sql);
        }
    }
742515
public function setRawValue(string $sql, string ...$params)
    {
        $instance = $this->updateQueryInstance();

        $instance->updateQuery()->setRaw($sql, ...$params);

        return $instance;
    }
247570
protected function bindValues(/*# string */ $sql, array $settings)/*# : string */
    {
        // init bindings
        $this->bindings = [];

        // bind values
        return $this->getBuilder()->getParameter()
            ->bindValues($sql, $this->bindings, $settings);
    }