来自 oracle 的 utf-8 数据和 php

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/19996077/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-25 20:20:20  来源:igfitidea点击:

Data from oracle in utf-8 with php

phporacle

提问by user2995287

i have a problem about getting data from oracle database. How to get data in utf-8? browser shows symbols with echo, but data from oracle has ? marks instead of letters

我有关于从 oracle 数据库获取数据的问题。如何获取utf-8格式的数据?浏览器显示带有回显的符号,但来自 oracle 的数据有 ? 标记而不是字母

    <head>
<meta http-equiv="content-type" content="text/html; charset=utf-8"></meta>
</head>
<?php

 $tns2 = "(DESCRIPTION = (ADDRESS = (PROTOCOL = TCP)(HOST = hostname)(PORT = 1521)) (CONNECT_DATA = (SID = sidname)))";
   if ($conn = oci_connect("user","pass", $tns2))
   {
       echo "YAY!";
       //oci_close($conn);
   }
   else
   {
       die("Nesiseka");
   }

$stid = oci_parse($conn, 'SELECT * rowname where rownum<=10');
oci_execute($stid);

oci_close($conn);

echo "<table border='1'>\n";
while ($row = oci_fetch_array($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {
    echo "<tr>\n";
    foreach ($row as $item) {
        echo "    <td>" . ($item !== null ? htmlentities($item, ENT_QUOTES) : "&nbsp;") . "</td>\n";
    }
    echo "</tr>\n";
}
echo "</table>\n";
echo"??????";
?>

回答by user2995287

Simple solution. Only add 'AL32UTF8' to line if ($conn = oci_connect(username,pass, $tns2 , 'AL32UTF8'))Everything works now. Thank you for help

简单的解决方案。只添加 'AL32UTF8' 到行if ($conn = oci_connect(username,pass, $tns2 , 'AL32UTF8'))现在一切正常。谢谢你的帮助

回答by dario

Use this to make database connection:

使用它来建立数据库连接:

$conn = oci_connect(username,pass, $tns2 , 'AL32UTF8')

回答by alok.kumar

set php encoding to utf 8

将 php 编码设置为 utf 8

mb_internal_encoding("UTF-8");

link for more http://php.net/manual/en/function.mb-internal-encoding.php

更多链接 http://php.net/manual/en/function.mb-internal-encoding.php