lithium\data\source\database\adapter\Sqlite3::encoding()

public method

Gets or sets the encoding for the connection.

Parameters

  • string $encoding

    If setting the encoding, this is the name of the encoding to set, i.e. 'utf8' or 'UTF-8' (both formats are valid).

Returns

mixed

If setting the encoding; returns true on success, or false on failure. When getting, returns the encoding as a string.

Source

	public function encoding($encoding = null) {
		$encodingMap = array('UTF-8' => 'utf8');

		if (!$encoding) {
			$query = $this->connection->query('PRAGMA encoding');
			$encoding = $query->fetchColumn();
			return ($key = array_search($encoding, $encodingMap)) ? $key : $encoding;
		}
		$encoding = isset($encodingMap[$encoding]) ? $encodingMap[$encoding] : $encoding;

		try {
			$this->connection->exec("PRAGMA encoding = \"{$encoding}\"");
			return true;
		} catch (PDOException $e) {
			return false;
		}
	}