lithium\data\source\database\adapter\MySql::encoding()
Getter/Setter for the connection's encoding.
MySQL 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 MySQL 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
$encodingEither
nullto 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 VARIABLES LIKE 'character_set_client'")
->fetchColumn(1);
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;
}