Ror and OCI8 encoding Problem - Ruby/Ruby On Rails(Archived)

Hello all! I have a problem with OCI8 and RoR, when I use select query to Orcle Data Base I take result where cyrilic characters are "?", and I can't decode this result, but when I create OCI8 conection in .rbx file on the server ( Linux) I take a right result whith cyrilic characters. This problem with Apache and Linux environment variables for OCI8? I think so. Halp please, whot I can do for solve this problem?
Oracle - encoding (win-1251)
Linux - encoding utf-8
Apache2 user in Linux - encoding koi8-u.
for use oci8 I write this rule for Apache:
Apache2 httpd.conf:
SetEnv LD_LIBRARY_PATH /opt/oracle/product/
SetEnv ORACLE_HOME /opt/oracle/product/ 

Thank for looking to the problem. I solve it when set Apache Environment variable:


NLS_LANG Problem get ???? when query

Hi alls,
My system's on
Linux RHEL3, PHP 5.0.3, Apache 2.0.52
I've problem about character set. The result shows ???? when I query thai language.
I've also set nls_lang in apache env, PHP _SERVER variables, PHP env variables.
But still get ???? .
Anybody help, pls.
Please try this

Problem with character-set

I'm connecting to a remote Oracle 9i server using the "Oracle 10g Instant Client" for Windows. It is used together with an Apache 2.0-server and PHP 5.0.5 on a Windows XP machine.
The problem is that I cannot store or retrieve entries from the database which contain special characters (in my case German umlauts). So when I do sth like this in PHP (I'm using PEAR::DB here, but I got the same results using the "pure" PHP-functions):
require_once 'DB.php';
$dsn = array('phptype'     => 'oci8', 'hostspec'     => '//host:port/sid',
               'username'     => 'user',
               'password'     => 'passwd',
               'new_link' => false);
$db = DB::connect($dsn, $options);
$res = $db->query("INSERT INTO test VALUES('äöüß')");
the row is inserted, but with ?'s instead of the umlauts. When I do the same from within SQLPlus, everything works fine and also SELECTing the row gives me the special characters.
When I try to SELECT this row inserted with SQLPlus using PHP, I get the question marks again.
Any hints?
In my php.ini:
And I got the following .dlls in my PATH:
I set the following environment variable on the windows machine (on which also Apache runs): NLS_LANG = GERMAN_GERMANY.WE8ISO8859P15
I also tried to play around with that value, but that seemed to have no effect.
Thanks for hints! 
Be sure you have the same character set in the Client and in the Server......... I should not be a problem........... I guess.... 
Try setting NLS_LANG to .AL32UTF8 before starting Apache. (note the dot at the start)
ie (assuming unix)
export NLS_LANG=.AL32UTF8
This worked for me.
(I found this in

Problems with accentuated characters while inserting into the database

I'm using PHP4 with Oracle 8.1. The application runs on Apache as the webserver. The application has 2 languages(English and Swedish) in different ports of the apache server, each language having its own set of tables in the oracle db.
Whenever I try to insert the swedish text into the database from within the PHP application, the special characters of the language gets stored as "?". However I've no problems when inserting/updating the swedish content using TOAD or SQLPLUS.
Can you please help me with this.
Call the script:
<?php phpinfo(); ?>and check that Oracle's standard globalization variables like NLS_LANG
are set in the Apache environment section.
The version of PHP you are using has the un-refactored oci8 extension.
I'd get the latest version from or and use that. It's a
drop in replacement with improved stability and performance.
-- cj 
These were the entries that I found in the Apache Environment section
HTTP_ACCEPT_CHARSET      ISO-8859-1,utf-8;q=0.7,*;q=0.7
HTTP_ACCEPT_ENCODING      gzip,deflate
HTTP_ACCEPT_LANGUAGE      en-us,en;q=0.5
Does this mean that the we may have to use the new OCI8 dlls that you mentioned.
You'll almost certainly need to have NLS_LANG set as you would have it
set in the environment when running SQL*Plus. There's a chapter on
PHP and Oracle globalization in
that is worth reviewing.
-- cj

char about PHP+ORCALE

my orcale's server:
my orcale's client:
i use sqldeveloper browse my data,her showed data that is right chinese
but i use php to connect orcale,her showed data that is not right chinese
can i set char when php connect? 
There is an optional fourth parameter to oci_connect() for the charset.
Alternatively, set NLS_LANG in the environment that starts the webserver.
Use <?php phpinfo(); ?> to check that the value is set in Apache's environment.
There is some information on i18n in
-- cj 
If you encountered Error "ORA-12705: Cannot access NLS data files or invalid environment specified". Or After insert UTF8 data into Oracle and the data became
NLS_LANG variables on both Oracle & Apache server must be the same to avoid unrecognized codes.
Try this:
1.Check environment NLS_LANG variable using phpinfo() to see what setting is on Web server.
2.Check Check environment NLS_LANG variable using set | grep LANG to see what setting is on Oracle.
In my example: NLS_LANG=American_America.UTF8 on both server

ORACLE UTF Chacter with PHP

i am using oracle9i and php 5.0 i cant insert a unicode charcter in oracle database via php. give any suggestion for this problem
See the globalization chapter in
If you further questions, post the code, the error and the versions of all the software
you are using.
-- cj 
i am using following sever set up
PHP Version 4.3.4
Oracle Version 9.2
Actually problem is i cant insert a extented character like "åånåååååååååå" in a oralce table via php pages but i excute a query directly in oracle its working fine , using php pages all extended character are inserted like this ¿¿n¿¿¿¿¿¿¿¿¿
i made a follwing setup in my linux server SuSE-9
a.In php server side we set default_charset =UTF-8 in php ini file
b.     We set an environment variable
c.     This ensures that the following HTTP header will be set in all PHP
Pages and consequently sent to the browser.
Content-Type: text/html; charset=UTF-8
d.     –enable-mbstring in php
e.     After enabling mbstring set mbstring.internal_encoding =UTF-8 in php ini file
f.     After enabling mbstring set mbstring.func_overload=7 in php ini file 
Did you ever find a resolution to this? I'm experiencing the exact same issue running a very similar setup (PHP 4, Ora 9.2). The PHP code worked perfectly up until we switched over the target tables to UTF-8 (specifically AL32UTF8). I'm now seeing the same Unicode data loss you described. 
You you using VARCHAR2 or NVARCHAR2? You should use VARCHAR2 and set database NLS_CHARACTERSET = AL32UTF8 during database creation.
NVARCHAR2 will not work, because it will be internally converted to VARCHAR2.
Environment variable NLS_LANG=AMERICAN_AMERICA.AL32UTF8 should be set before starting apache. putenv will not work in this case.
Make sure that page content type is set to "Content-Type: text/html; charset=UTF-8"
For me it is working fine.
I also am experiencing the exact same issue in a Windows2003/IIS6 environment. Whenever I insert UTF8 data through PHP I get data loss but inserting it directly through Toad or ODBC client the data is inserted correctly.
I'm using
-Varchar2 in the DB
-Page Content Type: Content-Type: text/html; charset=UTF-8
But the problem still persists 
There is a discussion of globalization in the Underground PHP and Oracle Manual. It is generic and doesn't discuss machine configuration - which is likely to be your problem. How are you setting/checking the NLS_LANG value?
-- cj 
Currently I have the NLS_LANG parameter set in the registry:
I have also set it in the Window's Environment variables and it behaves the same.
I tested the NLS_LANG setting by performing an insert with other Oracle clients (such asToad, SQLPLUS, Oracle ODBC Test, etc) and they all insert the data correctly. When the NLS_LANG parameter is not set properly, the data is not inserted correctly through these tools. 
This is a little late, but...
I found that I had to explicity specify the character set in PHP when connecting to Oracle to get proper UTF-8 data out (Linux machine w/ Oracle 10g xe).
For example:
$tns = '//localhost/XE';
$db_charset = 'AL32UTF8';
$link = oci_connect("$db_user", "$db_pass", "$tns", "$charset");
I had Oracle 10g xe on a Windows machine before and it was NOT necessary to specify the $charset.