public method

Getter/Setter for the connection's encoding.

Sqlite 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 Sqlite 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.


  • 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.



When $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.


	public function encoding($encoding = null) {
		if ($encoding === null) {
			$encoding = $this->connection
				->query('PRAGMA encoding')

			return $encoding === 'utf8' ? 'UTF-8' : $encoding;
		if (strcasecmp($encoding, 'utf-8') === 0 || strcasecmp($encoding, 'utf8') === 0) {
			$encoding = 'utf8';
		return $this->connection->exec("PRAGMA encoding = \"{$encoding}\"") !== false;