使用 php 从 MS Access 数据库中提取韩文字符时不显示

发布于 2024-12-29 18:45:45 字数 1345 浏览 1 评论 0原文

我有一个 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

无人问我粥可暖 2025-01-05 18:45:45

好的,我找到了解决方案。我必须像这样设置数据库连接的编码:

$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!

陌伤ぢ 2025-01-05 18:45:45

$con = new COM("ADODB.Connection", NULL, CP_UTF8);

也会起作用。

COM::__construct ( string $module_name [, mixed $server_name [, int $codepage [, string $typelib ]]] )

$module_name = "ADODB.Connection"
$server_name = NULL (using default, localmachine)
$codepage = CP_UTF8

请参阅http://php.net/manual/en/class.com.php

$con = new COM ("ADODB.Connection", NULL, CP_UTF8);

will work too.

COM::__construct ( string $module_name [, mixed $server_name [, int $codepage [, string $typelib ]]] )

$module_name = "ADODB.Connection"
$server_name = NULL (using default, localmachine)
$codepage = CP_UTF8

see http://php.net/manual/en/class.com.php

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文