Gdn_SQLDriver::set PHP Method

set() public method

Adds values to the $this->_Sets collection. Allows for the inserting and updating of values to the db.
public set ( mixed $Field, string $Value = '', boolean $EscapeString = true, boolean $CreateNewNamedParameter = true ) : Gdn_SQLDriver
$Field mixed The name of the field to save value as. Alternately this can be an array of $FieldName => $Value pairs, or even an object of $DataSet->Field properties containing one rowset.
$Value string The value to be set in $Field. Ignored if $Field was an array or object.
$EscapeString boolean A boolean value indicating if the $Value(s) should be escaped or not.
$CreateNewNamedParameter boolean A boolean value indicating that if (a) a named parameter is being created, and (b) that name already exists in $this->_NamedParameters collection, then a new one should be created rather than overwriting the existing one.
return Gdn_SQLDriver $this Returns this for fluent calls
    public function set($Field, $Value = '', $EscapeString = true, $CreateNewNamedParameter = true)
    {
        $Field = Gdn_Format::objectAsArray($Field);
        if (!is_array($Field)) {
            $Field = array($Field => $Value);
        }
        foreach ($Field as $f => $v) {
            if (is_array($v) || is_object($v)) {
                throw new Exception('Invalid value type (' . gettype($v) . ') in INSERT/UPDATE statement.', 500);
            } else {
                if (in_array(substr($f, -1), ['+', '-'], true)) {
                    // This is an increment/decrement.
                    $op = substr($f, -1);
                    $f = substr($f, 0, -1);
                    $parameter = $this->namedParameter($f, $CreateNewNamedParameter);
                    $this->_NamedParameters[$parameter] = $v;
                    $this->_Sets[$this->escapeIdentifier($f)] = $this->escapeIdentifier($f) . " {$op} " . $parameter;
                } elseif ($EscapeString) {
                    $NamedParameter = $this->namedParameter($f, $CreateNewNamedParameter);
                    $this->_NamedParameters[$NamedParameter] = $v;
                    $this->_Sets[$this->escapeIdentifier($f)] = $NamedParameter;
                } else {
                    $this->_Sets[$this->escapeIdentifier($f)] = $v;
                }
            }
        }
        return $this;
    }