lithium\data\source\database\adapter\PostgreSql::encoding PHP Method

encoding() public method

Gets or sets the encoding for the connection.
public encoding ( $encoding = null ) : mixed
$encoding
return mixed If setting the encoding; returns true on success, else false. When getting, returns the encoding.
    public function encoding($encoding = null)
    {
        $encodingMap = array('UTF-8' => 'UTF8');
        if (empty($encoding)) {
            $query = $this->connection->query("SHOW client_encoding");
            $encoding = $query->fetchColumn();
            return ($key = array_search($encoding, $encodingMap)) ? $key : $encoding;
        }
        $encoding = isset($encodingMap[$encoding]) ? $encodingMap[$encoding] : $encoding;
        try {
            $this->connection->exec("SET NAMES '{$encoding}'");
            return true;
        } catch (PDOException $e) {
            return false;
        }
    }