lithium\data\source\database\adapter\PostgreSql::encoding()
Getter/Setter for the connection's encoding.
PostgreSQL uses the string UTF8
to identify the UTF-8 encoding. In general UTF-8
is used
to identify that encoding. This methods allows both strings to be used for setting the
encoding (in lower and uppercase, with or without dash) and will transparently convert
to PostgreSQL native format. When getting the encoding, it is converted back into UTF-8
.
So that this method should ever only return UTF-8
when the encoding is used.
Parameters
-
null|string
$encoding
Either
null
to retrieve the current encoding, or a string to set the current encoding to. For UTF-8 accepts any permutation.
Returns
string|booleanWhen $encoding is null
returns the current encoding
in effect, otherwise a boolean indicating if setting the encoding
succeeded or failed. Returns 'UTF-8'
when this encoding is used.
Source
public function encoding($encoding = null) {
if ($encoding === null) {
$encoding = $this->connection
->query('SHOW client_encoding')
->fetchColumn();
return $encoding === 'UTF8' ? 'UTF-8' : $encoding;
}
if (strcasecmp($encoding, 'utf-8') === 0 || strcasecmp($encoding, 'utf8') === 0) {
$encoding = 'UTF8';
}
return $this->connection->exec("SET NAMES '{$encoding}'") !== false;
}