- 论坛徽章:
- 0
|
5555,我该用什么字符集??
跟pgadmin、postgresql没关系,以下是本人在win2000、postgresql8下的测试,估计在linux/unix环境下有差异:
表数据、结构:
--
-- PostgreSQL database dump
--
SET client_encoding = 'UNICODE';
SET check_function_bodies = false;
SET client_min_messages = warning;
SET search_path = public, pg_catalog;
SET default_tablespace = '';
SET default_with_oids = true;
--
-- Name: weather; Type: TABLE; Schema: public; Owner: lzh; Tablespace:
--
CREATE TABLE weather (
city character varying(80),
temp_lo integer,
temp_hi integer,
prcp real,
date date
);
ALTER TABLE public.weather OWNER TO lzh;
--
-- Data for Name: weather; Type: TABLE DATA; Schema: public; Owner: lzh
--
COPY weather (city, temp_lo, temp_hi, prcp, date) FROM stdin;
San Francisco 46 50 0.25 1994-11-27
San Francisco 43 57 0 1994-11-29
北方区 37 54 0.25 1994-11-29
\.
php测试代码:
<?php
header( 'Content-Type: text/html; charset=utf-8' );
$conn = pg_connect( 'host=localhost port=5432 dbname=lzh user=lzh password=lzh' );
$key = iconv( 'gb2312', 'utf-8', '北方区' );
$result = pg_query( "select * from weather where city = '$key'" );
$array = array();
while( $array = pg_fetch_array( $result ) )
{
print_r( $array );
}
pg_free_result( $result );
pg_close( $conn );
?>;
无论用like或者=,无论字段值的长度,中英文混合,测试均正常。 |
|