<?php
header("Content-type: text/html; charset=utf-8");
function db_connect() {
$result = new mysqli('localhost', 'wxgz1web', 'DEE42FD1', 'wxgz1');
mysql_query("SET NAMES 'utf8'"); if (!$result) {
throw new Exception('Could not connect to database server');
} else {
return $result;
}
}
$conn = db_connect();
$result = $conn->query("select username
from uc_members");
if (!$result) {
return false;
} //create an array of the URLs
$url_array = array();
for ($count = 1; $row = $result->fetch_row(); ++$count) {
$url_array[$count] = $row[0];
}
foreach ($url_array as $url) {
echo $url; echo "我们";
}
?>
结果是 ??我们SSSSSS我们
数据库中的中文是乱码, 用 phpmyadmin 看是正常的
我错在哪里?
header("Content-type: text/html; charset=utf-8");
function db_connect() {
$result = new mysqli('localhost', 'wxgz1web', 'DEE42FD1', 'wxgz1');
mysql_query("SET NAMES 'utf8'"); if (!$result) {
throw new Exception('Could not connect to database server');
} else {
return $result;
}
}
$conn = db_connect();
$result = $conn->query("select username
from uc_members");
if (!$result) {
return false;
} //create an array of the URLs
$url_array = array();
for ($count = 1; $row = $result->fetch_row(); ++$count) {
$url_array[$count] = $row[0];
}
foreach ($url_array as $url) {
echo $url; echo "我们";
}
?>
结果是 ??我们SSSSSS我们
数据库中的中文是乱码, 用 phpmyadmin 看是正常的
我错在哪里?
就是用我上面的代码 是乱码
插入数据
$conn1 = db_connect(); $result = $conn1->query("insert into uc_members values('周闪')");结果是 utf8下是 �����
gb2312是 邋邋邋
mysql_query("SET NAMES 'utf8'"); 的问题