1

我在数据库(MS SQL Server)中有一些字段,有时也有日语数据/字符。当我使用 php 检索它们时,数据变成 ???? 比如我有一个存储“BMW and JAPANESE CHARACTER”的字段模型,当涉及到页面时它变成“BMW and ????????”

以下是我的代码;

     include ('org_dataDSN.php');
     //Setting up database virtual connection
    echo "Connecting Database <br>";
    header( 'Content-Type: text/html; charset=utf-8' ); 
   echo "Successfully connected....";

    $subQuery="select model, make from infChnge_CS2002";
    $subRes=odbc_exec($connect, $subQuery);

    $ix=odbc_num_rows($subRes);
    echo "Success.." . $ix;
    while(odbc_fetch_row($subRes))
    {
$cstate = odbc_result($subRes, 1);
$sname = odbc_result($subRes, 2);

echo  $cstate . "<br>";
echo $sname . "";
    }

 odbc_close($connect);

      ?>
4

2 回答 2

0

首先使用 cast 函数在 MSSQL 查询中转换数据

SELECT CAST(model AS TEXT) as model, CAST(make AS TEXT) as make, FROM r_table;

在 php 中,将转换后的数据转换为 utf-8:

$model = iconv('CP1255', 'UTF-8', $model);
$make  = iconv('CP1255', 'UTF-8', $make);
于 2017-08-09T03:56:31.820 回答
-1

我用这个来纠正mysql连接??????波斯语

    $connect=mysql_connect('localhost','root','');
    mysql_query("SET NAMES 'utf8'", $connect);

在创建与服务器的连接后立即查询此“SET NAMES 'utf8'”

于 2013-09-23T09:58:24.450 回答