<?php
// 连接,选择数据库
$dbconn = pg_connect("host=localhost dbname=publishing user=www password=foo")
or die('Could not connect: ' . pg_last_error());
// 执行 SQL 查询
$query = 'SELECT * FROM authors';
$result = pg_query($query) or die('Query failed: ' . pg_last_error());
// 用 HTML 显示结果
echo "<table>/n";
while ($line = pg_fetch_array($result, null, PGSQL_ASSOC)) {
echo "/t<tr>/n";
foreach ($line as $col_value) {
echo "/t/t<td>$col_value</td>/n";
}
echo "/t</tr>/n";
}
echo "</table>/n";
// 释放结果集
pg_free_result($result);
// 关闭连接
pg_close($dbconn);
?>
http://php.chinaunix.net/manual/zh/ref.pgsql.php
ps:页面申明编码:在HTML代码HEAD里面,可以用<meta http-equiv="Content-Type" content="text/html;
charset="XXX" />来告诉浏览器网页采用了什么编码,目前中文网站开发中主要用的是GB2312和UTF-8两种编
码。
提取的数据编码与 "<META http-equiv=Content-Type content="text/html; charset=gb2312">" 网页页面
编码一致,这样网页中就没有乱码了。
$db->query("set client_encoding to 'gbk'");
如果不想改配置文件
在页面代码中加入效果一样!
原来是这样,可以设置客户端编码的,我一直给数据库定义为
[code]
CREATE DATABASE hent
WITH OWNER = postgres
ENCODING = 'EUC_CN'
TABLESPACE = pg_default;
[/code]
改三个配置文件即可.其实大家都知道是哪三个了.
php.ini my.cnf httpd.conf 就好了.把编码有关的都设置成 utf-8即可.
但是还不行.因为我安装了. php-mbstring .所以在php.ini里面一定要开启 mbstring 且编码也要设置成
utf-8.
php.ini ;default_charset = "iso-8859-1" 改成 default_charset = "UTF-8"
<?
header('content-Type=text/html;charset=utf-8')
php
echo "test中文测试";
?>
如果你把文件保存为ANSI格式的话
<?
header('content-Type=text/html;charset=GB2312')
php
echo "test中文测试";
?>
<?php
header('Content-Type:text/html;charset=GB2312');
echo "test中文测试";
?>
<?
$charset = "utf-8";
header("Content-type: text/xml; charset=$charset");
有用的网站:http://blog.csdn.net/Zoohua/archive/2009/10/18/4693024.aspx