lithium\data\source\database\adapter\MySql::encoding()
Implements
lithium\data\source\Database::encoding()
Gets or sets the encoding for the connection.
Parameters
-
$encoding
Returns
mixedIf setting the encoding; returns true on success, else false. When getting, returns the encoding.
Source
public function encoding($encoding = null) {
$encodingMap = array('UTF-8' => 'utf8');
if (empty($encoding)) {
$query = $this->connection->query("SHOW VARIABLES LIKE 'character_set_client'");
$encoding = $query->fetchColumn(1);
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;
}
}