Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Data from oracle in utf-8 with php

Tags:

php

oracle

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"įęėšųį";
?>
like image 487
user2995287 Avatar asked Nov 15 '13 07:11

user2995287


People also ask

Can PHP be used with Oracle Database?

PHP is a popular web scripting language, and is often used to create database-driven web sites. This tutorial helps you get started with PHP and Oracle Database by showing how to build a web application and by giving techniques for using PHP with Oracle.

What is UTF8 data?

UTF-8 is a variable-width Unicode encoding that encodes each valid Unicode code point using one to four 8-bit bytes. UTF-8 has many desirable properties, including that it is backwards compatible with ASCII, often provides a more compact representation of Unicode data than UTF-16, and is endianness independent.

Does Oracle use Unicode?

The Oracle Data Provider for . NET enables programs running in any . NET programming environment on Windows platforms to access Unicode data stored in SQL CHAR and NCHAR data types. It provides UTF-16 data access through Unicode data types.

What is AL32UTF8 character set Oracle?

The AL32UTF8 character set supports 1-byte, 2-byte, 3-byte, and 4-byte values. The UTF8 character set supports 1-byte, 2-byte, and 3-byte values, but not 4-byte values. AL32UTF8 is a superset of UTF8 as it can support 4-byte values.


1 Answers

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

like image 140
user2995287 Avatar answered Sep 25 '22 23:09

user2995287