Quote a database table name and adds the table prefix if needed.

$table = $db->quote_table($table);

@param   mixed $value table name or array(table, alias)

@return  string

@uses    static::quote_identifier
@uses    static::table_prefix
345127
public function quote_table($value)
	{
		// Assign the table by reference from the value
		if (is_array($value))
		{
			$table =& $value[0];

			// Attach table prefix to alias
			$value[1] = $this->table_prefix().$value[1];
		}
		else
		{
			$table =& $value;
		}

		// deal with the sub-query objects first
		if ($table instanceof Database_Query)
		{
			// Create a sub-query
			$table = '('.$table->compile($this).')';
		}
		elseif (is_string($table))
		{
			if (strpos($table, '.') === false)
			{
				// Add the table prefix for tables
				$table = $this->quote_identifier($this->table_prefix().$table);
			}
			else
			{
				// Split the identifier into the individual parts
				$parts = explode('.', $table);

				if ($prefix = $this->table_prefix())
				{
					// Get the offset of the table name, 2nd-to-last part
					// This works for databases that can have 3 identifiers (Postgre)
					if (($offset = count($parts)) == 2)
					{
						$offset = 1;
					}
					else
					{
						$offset = $offset - 2;
					}

					// Add the table prefix to the table name
					$parts[$offset] = $prefix.$parts[$offset];
				}

				// Quote each of the parts
				$table = implode('.', array_map(array($this, 'quote_identifier'), $parts));
			}
		}

		// process the alias if present
		if (is_array($value))
		{
			// Separate the column and alias
			list ($value, $alias) = $value;

			return $value.' AS '.$this->quote_identifier($alias);
		}
		else
		{
			// return the value
			return $value;
		}
	}
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);
		}
360741
function prepValueForDB($value) {
		if(!$this->nullifyEmpty && $value === '') {
			return DB::getConn()->prepStringForDB($value);
		} else {
			return parent::prepValueForDB($value);
		}
	}
10464
protected function _quote($value)
    {
        if (is_int($value) || is_float($value)) {
            return $value;
        }
        $this->_connect();
        return "'" . $this->_connection->real_escape_string($value) . "'";
    }
999349
public function quote($value)
    {
        if (is_array($value)) {
            $result = [];
            foreach ($value as $single) {
                $result[] = $this->quote($single);
            }
            return sprintf(
                '(%s)',
                implode(', ', $result)
            );
        } else {
            return $this->pdo->quote($value);
        }
    }
269688
function quote( $value ) {

        $value = $this->format( $value );

        if ( $value === null ) {

            return "NULL";

        }

        if ( $value === false ) {

            return "'0'";

        }

        if ( $value === true ) {

            return "'1'";

        }

        if ( is_int( $value ) ) {

            return "'" . ( (string) $value ) . "'";

        }

        if ( is_float( $value ) ) {

            return "'" . sprintf( "%F", $value ) . "'";

        }

        if ( $value instanceof Literal ) {

            return $value->value;

        }

        return $this->pdo->quote( $value );

    }
717635
public static function quote($value, $empty = 'NULL')
    {
        if (is_array($value)) return '(' . join(', ', array_map(array(get_class(), 'quote'), $value)) . ')';

        if (is_null($value)) return $empty;
        if (is_bool($value)) return $value ? 'TRUE' : 'FALSE';
        if (is_int($value) || is_float($value)) return (string)$value;
        return '"' . strtr((string)$value, array('\\' => '\\\\', "\0" => '\\0', "\r" => '\\r', "\n" => '\\n', '"' => '\\"')) . '"';
    }
481370
public function ident($value, $quote = '`')
    {
        $value = preg_replace('/[^A-Za-z0-9_]+/', '', $value);
        if (strpos($value, '.') !== false) {
            $values = explode('.', $value);
            $value = $quote . implode($quote . '.' . $quote, $values) . $quote;
        } else {
            $value = $quote . $value . $quote;
        }

        return $value;
    }
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;
    }
633136
protected function quote($conn, $value)
    {
        if ($conn instanceof PDO) {
            return $conn->quote($value);
        } elseif (is_resource($conn)) {
            $value = str_replace("'", "''", $value);
            $value = str_replace("\0", "[NULL]", $value);
            return "N'$value'";
        } else {
            user_error('Invalid database connection', E_USER_ERROR);
        }
        return null;
    }
115163
public function prefixTables($table, bool $use_identifier = false)
    {
        if ($table instanceof \Closure || is_resource($table)) {
            throw new \InvalidArgumentException(
                "Invalid value to be quote, table value could not be instance of `Closure` or as a `Resource`",
                E_USER_ERROR
            );
        }

        $prefix = $this->getTablePrefix();
        if (is_array($table)) {
            foreach ($table as $key => $value) {
                $table[$key] = $this->prefixTables($value, $use_identifier);
            }
            return $table;
        }
        if (is_object($table)) {
            foreach (get_object_vars($table) as $key => $value) {
                $table->{$key} = $this->prefixTables($value, $use_identifier);
            }
            return $table;
        }
        if (!is_string($table)) {
            return null;
        }
        if (strpos($table, $this->currentQuoteIdentifier) !== false) {
            $use_identifier = true;
        }
        if (!empty($prefix) && is_string($prefix) && trim($prefix)) {
            $tableArray = explode('.', $table);
            $tableArray    = $this->trimTableSelector($tableArray);
            if (count($tableArray) > 1) {
                $connectionParams = $this->getConnectionParams();
                if (isset($connectionParams['dbname']) && $tableArray[0] == $connectionParams['dbname']) {
                    $tableArray[1] = $this->prefixTableCallback($tableArray);
                }
                if ($use_identifier) {
                    return $this->currentQuoteIdentifier
                           . implode("{$this->currentQuoteIdentifier}.{$this->currentQuoteIdentifier}", $tableArray)
                           . $this->currentQuoteIdentifier;
                } else {
                    return implode(".", $tableArray);
                }
            } else {
                $table = $this->prefixTableCallback($tableArray[0]);
            }
        }

        return $use_identifier
            ? $this->currentQuoteIdentifier.$table.$this->currentQuoteIdentifier
            : $table;
    }
452809
protected function getQuoteValue($value): string
    {
        $key = uniqid();
        $this->builder->setParameter($key, $value);

        return ":{$key}";
    }
157924
public static function escapeString($value)
    {
        if (version_compare(VERSION, '4.0', '<'))
        {
            $db = \Contao\Database::getInstance();

            if ($db instanceof \Contao\Database\Mysqli)
            {
                $db    = Contao3MysqliHelper::getInstance();
                $value = "'" . $db->getConnection()->real_escape_string($value) . "'";
            }
            else
            {
                if ($db instanceof \Contao\Database\Mysql)
                {
                    $db    = Contao3MysqlHelper::getInstance();
                    $value = "'" . mysql_real_escape_string($value, $db->getConnection()) . "'";
                }
            }
        }
        else
        {
            $connection = System::getContainer()->get('database_connection');
            $value      = $connection->quote($value);
        }

        return $value;
    }
1198606
protected function _quote($value)
    {
        if (is_int($value)) {
            return $value;
        } elseif (is_float($value)) {
            return sprintf('%F', $value);
        }

        return "'" . str_replace("'", "''", $value) . "'";
    }
522573
protected function _quote($value)
    {
        if (is_int($value)) {
            return $value;
        } elseif (is_float($value)) {
            return sprintf('%F', $value);
        }
        return "'" . addcslashes($value, "\000\n\r\\'\"\032") . "'";
    }
314252
public static function quoteDecimal($value): string
  {
    if ($value===null || $value==='') return 'null';

    if (is_int($value) || is_float($value)) return (string)$value;

    return "'".self::$mysqli->real_escape_string($value)."'";
  }
197572
public function escapeAndQuote($value)
    {
        if (null === $value) {
            $pdoType = \PDO::PARAM_NULL;
        } else {
            $pdoType = \PDO::PARAM_STR;
        }

        return $this->getPdo()->quote($value, $pdoType);
    }