array ( 0 => 'index.php', 1 => 'PHP Manual', ), 'head' => array ( 0 => 'UTF-8', 1 => 'zh', ), 'this' => array ( 0 => 'function.pg-set-client-encoding.php', 1 => 'pg_set_client_encoding', ), 'up' => array ( 0 => 'ref.pgsql.php', 1 => 'PostgreSQL 函数', ), 'prev' => array ( 0 => 'function.pg-send-query.php', 1 => 'pg_send_query', ), 'next' => array ( 0 => 'function.pg-set-error-context-visibility.php', 1 => 'pg_set_error_context_visibility', ), 'alternatives' => array ( ), 'source' => array ( 'lang' => 'zh', 'path' => 'reference/pgsql/functions/pg-set-client-encoding.xml', ), ); $setup["toc"] = $TOC; $setup["toc_deprecated"] = $TOC_DEPRECATED; $setup["parents"] = $PARENTS; manual_setup($setup); ?>
(PHP 4 >= 4.0.3, PHP 5, PHP 7, PHP 8)
pg_set_client_encoding — 设定客户端编码
pg_set_client_encoding() 设定客户端编码,成功返回 0,出错返回 -1。
PostgreSQL 会自动将后端数据库编码中的数据转换成前端编码。
注意:
本函数以前的名字为 pg_setclientencoding()。
connection
An PgSql\Connection instance.
When connection
is unspecified, the default connection is used.
The default connection is the last connection made by pg_connect()
or pg_pconnect().
As of PHP 8.1.0, using the default connection is deprecated.
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
。
版本 | 说明 |
---|---|
8.1.0 |
现在 connection 参数接受 PgSql\Connection
实例,之前接受 resource。
|
示例 #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";
}
?>