设置编码
void|boolean Driver_Database_Driver_Postgre::set_charset( string $charset )
参数列表
参数 类型 描述 默认值 $charset
string
$charset
void|boolean
public function set_charset($charset)
{
if (!$charset)return;
$connection_id = $this->connection_id();
$connection = Database_Driver_Postgre::$_connection_instance[$connection_id];
if (!$connection_id || !$connection)
{
$this->connect();
$this->set_charset($charset);
return;
}
if (isset(Database_Driver_Postgre::$_current_charset[$connection_id]) && $charset == Database_Driver_Postgre::$_current_charset[$connection_id])
{
return true;
}
if (pg_set_client_encoding($connection, $charset) === 0)
{
throw new Exception('Error:' . pg_last_error($connection));
}
# 记录当前设置的编码
Database_Driver_Postgre::$_current_charset[$connection_id] = $charset;
}