Hi, I am trying to save names in an Oracle database and return them using PHP and oci8.
However, if I insert é directly into the Oracle database and use oci8 to return it, I just get e
Do I have to encode all special characters (including é ) into html objects (i.e.: é ) before pasting into the database ... or am I missing something?
thanks
UPDATE: March 1 at 18:40
found this function: http://www.php.net/manual/en/function.utf8-decode.php#85034
function charset_decode_utf_8($string) { if(@!ereg("[\200-\237]",$string) && @!ereg("[\241-\377]",$string)) { return $string; } $string = preg_replace("/([\340-\357])([\200-\277])([\200-\277])/e","'&#'.((ord('\\1')-224)*4096 + (ord('\\2')-128)*64 + (ord('\\3')-128)).';'",$string); $string = preg_replace("/([\300-\337])([\200-\277])/e","'&#'.((ord('\\1')-192)*64+(ord('\\2')-128)).';'",$string); return $string; }
seems to work, although not sure if its optimal solution
UPDATE: March 8 at 3:45 pm
Oracle Character Set - ISO-8859-1.
in PHP I added:
putenv("NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1");
to force the oci8 connection to use this character set. Getting é using oci8 from PHP now worked! (for varchars , but not CLOBs had to do utf8_encode to extract it)
So, I tried to save data from PHP to Oracle ... and it does not work. Elsewhere on the way from PHP to Oracle é becomes ?
UPDATE: March 9 at 2:47 p.m.
So take a closer look. After adding the NLS_LANG variable, doing oci8 direct attachments with é works.
The problem is actually on the PHP side. Using the ExtJs framework, when submitting a form, it encodes it using encodeURIComponent .
Therefore, é sent as %C3%A9 , and then transcoded to é .
However, the length is now 2 (strlen($my_sent_value) = 2) , not 1. And if in PHP I try: $ my_sent_value == é = FALSE
I think that if I can recode all these characters in PHP back to a byte length of size 1 and then paste them into Oracle, it should work.
Still no luck though
UPDATE: March 10 at 11:05
I keep thinking that I'm so close (still so far).
putenv("NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P9"); works very sporadically.
I created a small php script for testing:
header('Content-Type: text/plain; charset=ISO-8859-1'); putenv("NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P9"); $conn= oci_connect("user", "pass", "DB"); $stmt = oci_parse($conn, "UPDATE temp_tb SET string_field = '|é|'"); oci_execute($stmt, OCI_COMMIT_ON_SUCCESS);
After running this one time and entering the Oracle database directly, I see that STRING_FIELD is set to |¿| . Obviously not what I expected from my previous experience.
However, if I refresh this PHP page twice ... it worked !!!
In Oracle, I saw |é| .
It seems that perhaps the environment variable was set incorrectly or sent during the first execution of the script, but is available for the second execution.
My next experiment is to export the variable to a PHP environment, however I need to reset Apache for this ... so we'll see what happens, hope it works.