简体   繁体   中英

Data from oracle in utf-8 with php

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

    <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"įęėšųį";
?>

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

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

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

set php encoding to utf 8

mb_internal_encoding("UTF-8");

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM