1、数据库的编码设为utf-8
打开数据库配置文件my.ini,在里面设置
2、执行mysql_query时添加
mysql_query("set names 'utf8'");
程序代码示例
打开数据库配置文件my.ini,在里面设置
[mysql]
default-character-set=utf8
[mysqld]
default-character-set=utf8
default-character-set=utf8
[mysqld]
default-character-set=utf8
mysql_query("set names 'utf8'");
程序代码示例
<?php
header("Content-Type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
echo "<contact>\n";
$con = mysql_connect("localhost", "user", "password");
if ($con) {
mysql_query("set names 'utf8'");
mysql_select_db("test", $con);
$rs = mysql_query("select * from member;", $con);
if ($rs) {
while($row = mysql_fetch_assoc($rs)) {
echo "<member id=\"$row[name]\">\n" .
"<name>$row[phone]</name>\n" .
"</member>\n";
}
mysql_free_result($rs);
}
mysql_close($con);
}
echo "</contact>";
?>
header("Content-Type: text/xml");
echo "<?xml version=\"1.0\" encoding=\"utf-8\" ?>\n";
echo "<contact>\n";
$con = mysql_connect("localhost", "user", "password");
if ($con) {
mysql_query("set names 'utf8'");
mysql_select_db("test", $con);
$rs = mysql_query("select * from member;", $con);
if ($rs) {
while($row = mysql_fetch_assoc($rs)) {
echo "<member id=\"$row[name]\">\n" .
"<name>$row[phone]</name>\n" .
"</member>\n";
}
mysql_free_result($rs);
}
mysql_close($con);
}
echo "</contact>";
?>
转载于:https://blog.51cto.com/isnowwolf/326022