pg_set_client_encoding
(PHP 4 >= 4.0.3, PHP 5, PHP 7)
pg_set_client_encoding — 设置客户端编码
描述
int pg_set_client_encoding ([ resource $connection ], string $encoding )
pg_set_client_encoding()设置客户端编码,如果成功则返回0,否则返回-1。
PostgreSQL会自动将后端数据库编码中的数据转换为前端编码。
注意:
该函数以前称为pg_setclientencoding()。
参数
connection
PostgreSQL数据库连接资源。如果connection
不存在,则使用默认连接。默认连接是pg_connect()或pg_pconnect()所做的最后一个连接。
encoding
所需的客户端编码。之一的SQL_ASCII,EUC_JP,EUC_CN,EUC_KR,EUC_TW,UNICODE,MULE_INTERNAL,LATINX(X = 1 ... 9),KOI8,WIN,ALT,SJIS,BIG5或WIN1250。
可用编码的确切列表取决于您的PostgreSQL版本,因此请查阅您的PostgreSQL手册以获取更具体的列表。
返回值
成功时返回0,错误时返回-1。
例子
示例#1 pg_set_client_encoding()示例
<?php
$conn = pg_pconnect("dbname=publisher");
if (!$conn) {
echo "An error occurred.\n";
exit;
}
// Set the client encoding to UNICODE. Data will be automatically
// converted from the backend encoding to the frontend.
pg_set_client_encoding($conn, "UNICODE");
$result = pg_query($conn, "SELECT author, email FROM authors");
if (!$result) {
echo "An error occurred.\n";
exit;
}
// Write out UTF-8 data
while ($row = pg_fetch_row($result)) {
echo "Author: $row[0] E-mail: $row[1]";
echo "<br />\n";
}
?>
本文档系腾讯云开发者社区成员共同维护,如有问题请联系 cloudcommunity@tencent.com