使用 php 从 MS Access 数据库中提取韩文字符时不显示
我有一个 Access 数据库,其中包含很多具有韩国名字的人。我有一个经典的 ASP 站点,它可以非常愉快地从数据库读取数据并正确显示它。我现在正在用 PHP 开发一个不同的网站,但它无法显示韩文字符。我编写了两个非常简单的脚本,一个用 ASP 编写,一个用 PHP 编写来找出原因。
ASP:
<%
Response.CodePage = 65001
Set objLoginConn = Server.CreateObject("ADODB.Connection")
objLoginConn.Provider = "Microsoft.Jet.OLEDB.4.0"
objLoginConn.Open "C:\wwwroot\mydb.mdb"
Set rs = Server.CreateObject("ADODB.Recordset")
SQL = "SELECT firstname FROM mytable"
rs.Open SQL, objLoginConn, 3, 3
while not rs.EOF
response.write("<p>"& rs.fields("firstname").value &"</p>")
rs.movenext
wend
%>
PHP:
<?php
$con = new COM("ADODB.Connection") or die("Cannot start ADO");
$con->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source = mydb.mdb");
$SQL = "SELECT firstname FROM mytable";
$rs = $con->execute($SQL);
while (!$rs->EOF) {
echo "<p>".$rs->Fields("firstname")->value."</p>";
$rs->movenext();
}
?>
ASP 脚本正确打印所有名称,但 PHP 脚本打印大量 ?。如果我从 ASP 脚本中删除 Response.CodePage = 65001
位,它会像 PHP 一样打印 ? 。
然后,我将注意力转向寻找 Response.CodePage = 65001 的 PHP 等效项,并发现了类似 header('Content-Type:text/html; charset=UTF-8');< /code> 和
ini_set('default_charset', 'UTF-8');
但他们没有完成这项工作。
有人能指出我正确的方向吗?
I have an Access DB which contains a lot of people with Korean names. I hava a classic ASP site that reads data from the DB quite happily and displays it properly. I am now developing a different site in PHP, but it is unable to display Korean characters. I have written two very simple scripts, one in ASP and one in PHP to work out why.
ASP:
<%
Response.CodePage = 65001
Set objLoginConn = Server.CreateObject("ADODB.Connection")
objLoginConn.Provider = "Microsoft.Jet.OLEDB.4.0"
objLoginConn.Open "C:\wwwroot\mydb.mdb"
Set rs = Server.CreateObject("ADODB.Recordset")
SQL = "SELECT firstname FROM mytable"
rs.Open SQL, objLoginConn, 3, 3
while not rs.EOF
response.write("<p>"& rs.fields("firstname").value &"</p>")
rs.movenext
wend
%>
PHP:
<?php
$con = new COM("ADODB.Connection") or die("Cannot start ADO");
$con->Open("Provider=Microsoft.Jet.OLEDB.4.0; Data Source = mydb.mdb");
$SQL = "SELECT firstname FROM mytable";
$rs = $con->execute($SQL);
while (!$rs->EOF) {
echo "<p>".$rs->Fields("firstname")->value."</p>";
$rs->movenext();
}
?>
The ASP script prints all the names correctly, but the PHP script prints a load of ?'s. If I remove the Response.CodePage = 65001
bit from the ASP script, it prints ?'s just like PHP.
I then turned my attention to finding a PHP equivilent of Response.CodePage = 65001
and found things like header('Content-Type:text/html; charset=UTF-8');
and ini_set('default_charset', 'UTF-8');
but they did not do the job.
Can anyone point me in the right direction?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
好的,我找到了解决方案。我必须像这样设置数据库连接的编码:
$con = new COM("ADODB.Connection", NULL, 65001);
其中
65001
是 utf- 8 我认为。不确定这是否是最好的方法,但它对我有用!Ok, i have found a solution. I had to set the encoding of the DB connection like so:
$con = new COM("ADODB.Connection", NULL, 65001);
where the
65001
is utf-8 i think. Not sure if this is the best way to go, but it works for me!$con = new COM("ADODB.Connection", NULL, CP_UTF8);
也会起作用。
请参阅http://php.net/manual/en/class.com.php
$con = new COM ("ADODB.Connection", NULL, CP_UTF8);
will work too.
see http://php.net/manual/en/class.com.php