选择语言 :

 Driver_Database_Driver_Postgre::set_charset

设置编码

void|boolean Driver_Database_Driver_Postgre::set_charset( string $charset )
throws
Exception

参数列表

参数 类型 描述 默认值
$charset string $charset
返回值
  • void|boolean
File: ./drivers/database/postgre/postgre.class.php
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;
}