Make sure that $value is escaped and quoted according to type and returned
as a string.

@param string $value a SQL parameter to escape
@return string a string that can safely be used in SQL queries
431476
protected function _quote( $value )
    {
        if ( $value === null )
            return 'NULL';
        elseif ( is_integer( $value ) )
        {
            return $this->db->quote( $value, PDO::PARAM_INT );
        }
        else
        {
            return $this->db->quote( $value, PDO::PARAM_STR );
        }
    }
206866
public function quoteValue($value): string
    {
        if ($value === null) {
            return 'NULL';
        }

        $result = $this->pdo->quote($value);

        if ($result === false) {
            throw new RuntimeException('The database driver does not support quoting in this way.');
        }

        return $result;
    }
206628
protected function formatValue($value)
    {
        if (PHP_VERSION_ID < 50400) {
            return str_replace('\/', '/', json_encode($value));
        }

        return json_encode($value, JSON_UNESCAPED_SLASHES | JSON_UNESCAPED_UNICODE);
    }
165405
public function quoteString(?string $value): string
  {
    if ($value===null || $value==='') return 'null';

    return "'".$this->mysqli->real_escape_string($value)."'";
  }
370011
private function encodeQuery(string $value): string
    {
        return preg_replace_callback(
            '/(?:[^'.self::UNRESERVED.self::SUB_DELIMS.':@%~\/\[\]\?]+|%(?![A-Fa-f0-9]{2}))/',
            function (array $match) {
                return rawurlencode($match[0]);
            },
            $value
        );
    }
371434
public function escape($value, $type){
		switch($type){
			case Manager::BOOL:
				return $value ? 'TRUE' : 'FALSE';

			case Manager::TEXT:
				return "'" . pg_escape_string($this->resource, $value) . "'";

			case Manager::BINARY:
				return "'" . pg_escape_bytea($this->resource, $value) . "'";

			case Manager::IDENTIFIER:
				return '"' . str_replace('.', '"."', str_replace('"', '""', $value)) . '"';

			case Manager::DATETIME:
				return ($value instanceof DateTime) ? $value->format("'Y-m-d H:i:s'") : date("'Y-m-d H:i:s'", $value);

			default:
				throw new InvalidArgumentException('Unsupported data type.');
				break;
		}
	}
394932
public function quote($value)
    {
        // If a PDO database connection is set, use it to quote the value using
        // the underlying database. Otherwise, quote it manually.
        if ($pdo = $this->getPdo()) {
            return $pdo->quote($value);
        }

        if (\is_numeric($value)) {
            return $value;
        }

        if (null === $value) {
            return 'NULL';
        }

        return "'" . \addslashes($value) . "'";
    }
485103
public function escapeHtml(string $value) : string
    {
        return htmlspecialchars($value, ENT_COMPAT, $this->encoding, false);
    }
191788
protected function secureValue( $value ){
#		if( !ini_get( 'magic_quotes_gpc' ) )
#			$value = addslashes( $value );
#		$value	= htmlentities( $value );
		if ( $value === NULL )
			return "NULL";
		$value	= $this->dbc->quote( $value );
		return $value;
	}
571902
public function mysqliStmtType($value) {
        $value = trim($value);
        if (!preg_match('/[^0-9\.]/', $value) && substr($value, 0, 1) != 0) {
            // d or i?
            return ctype_digit($value) ? 'i' : 'd';
        }
        return 's';
    }
120251
private function escapeObject($value) {
        if (!is_object($value)) {
            return $value;
        }
        if (isset($value->escape) && $value->escape === false) {
            return $value;
        }
        if ($value instanceof Entity) {
            $errors = $value->getErrors();
            $invalid = $value->getInvalid();
            $properties = $value->visibleProperties();
            foreach ($properties as $prop) {
                // To not use the entity setter
                $value->set($prop, $this->escape($value->{$prop}), ['setter' => false]);
            }
            foreach($errors as $field => $err) {
                $value->setError($field, $err);
            }
            $value->setInvalid($invalid);
            return $value;
        }

        if ($this->hasIterator($value)) {
            foreach ($value as $key => $prop) {
                $value->{$key} = $this->escape($prop);
            }
            return $value;
        }

        return $value;
    }
197572
public function escapeAndQuote($value)
    {
        if (null === $value) {
            $pdoType = \PDO::PARAM_NULL;
        } else {
            $pdoType = \PDO::PARAM_STR;
        }

        return $this->getPdo()->quote($value, $pdoType);
    }
978907
public String escapeValue(String value) {
		StringBuilder sb = new StringBuilder(value.length() + 4);
		databaseType.appendEscapedWord(sb, value);
		return sb.toString();
	}
776966
public function wrap($value)
		{
			// Expressions should be injected into the query as raw strings so
			// so we do not want to wrap them in any way. We will just return
			// the string value from the expression to be included.
			if ($value instanceof Expression) return $value->get();

			// If the value being wrapped contains a column alias, we need to
			// wrap it a little differently as each segment must be wrapped
			// and not the entire string.
			if (strpos(strtolower($value), ' as ') !== false) {
				$segments = explode(' ', $value);

				return sprintf(
					'%s AS %s',
					$this->wrap($segments[0]),
					$this->wrap($segments[2])
				);
			}

			// Since columns may be prefixed with their corresponding table
			// name so as to not make them ambiguous, we will need to wrap
			// the table and the column in keyword identifiers.
			foreach (explode('.', $value) as $segment) {
				if ($segment == '*') {
					$wrapped[] = $segment;
				} else {
					$wrapped[] = sprintf($this->wrapper, $segment);
				}
			}

			return implode('.', $wrapped);
		}
1199643
protected static function sanitiseVariableValue($value)
        {
            $value = trim($value);

            if (!$value) {
                return '';
            }

            if (strpbrk($value[0], '"\'') !== false) { // value starts with a quote
                $quote = $value[0];

                $regexPattern = sprintf('/^
                    %1$s          # match a quote at the start of the value
                    (             # capturing sub-pattern used
                     (?:          # we do not need to capture this
                      [^%1$s\\\\] # any character other than a quote or backslash
                      |\\\\\\\\   # or two backslashes together
                      |\\\\%1$s   # or an escaped quote e.g \"
                     )*           # as many characters that match the previous rules
                    )             # end of the capturing sub-pattern
                    %1$s          # and the closing quote
                    .*$           # and discard any string after the closing quote
                    /mx',
                    $quote
                );

                $value = preg_replace($regexPattern, '$1', $value);
                $value = str_replace("\\$quote", $quote, $value);
                $value = str_replace('\\\\', '\\', $value);
            } else {
                $parts = explode(' #', $value, 2);
                $value = $parts[0];
            }

            return trim($value);
        }
945817
public static function escape( $value )
	{
		if ( $value instanceof Htmlable )
			return $value->toHtml();

		return htmlentities( $value, ENT_QUOTES, 'UTF-8', false );
	}
982042
static public function formatSearch($value)
    {
        $value = static::filter_xss($value);
        $value = static::html_entities($value);
        $value = str_replace('&lt;', '', $value);
        $value = str_replace('&gt;', '', $value);
        $value = static::sql_encode($value);
        $value = trim($value);
        
        return $value;
    }