[eluser]Unknown[/eluser]
I’m new at CI Forums, but I’d like to share a update that I’ve made to the PostGreSQL driver.
When you configure your database to use PG and sets a charset (LATIN1, LATIN2, etc), the charset isn’t setted (there’s a TODO comment about it in the code).
So I used the MySQL driver as reference to implement in the PostGreSQL driver (
system/database/drivers/postgre/postgre_driver.php).
I’d like to receive comments about it, because I’m new both with CI and PostGreSQL, and this solved the problem I’m working with, and can solve to other people too, but I didn’t have time to test it with enviroments different from my own.
Code:
function db_set_charset($charset, $collation)
{
// @todo - add support if needed
// return TRUE;
if ( ! isset($this->use_set_encoding))
{
// pg_set_client_encoding() requires PHP >= 4.0.3 and PostGreSQL >= 7.0, use SET ENCODING as fallback
$pgVersion = pg_version();
$this->use_set_encoding = (version_compare(PHP_VERSION, '4.0.3', '>=') && version_compare($pgVersion['client'], '7.0', '>=')) ? FALSE : TRUE;
}
if ($this->use_set_encoding === TRUE)
{
return @pg_query($this->conn_id, "set client_encoding to '" . $this->escape_str($charset) . "'");
}
else
{
return @pg_set_client_encoding ($this->conn_id, $charset);
}
}