#36797 [Asn]: Problem using UTF-8 database with pdo_oci

From: Date: Wed, 06 Jun 2007 20:02:21 +0000
Subject: #36797 [Asn]: Problem using UTF-8 database with pdo_oci
References: 1  Groups: php.bugs 
Request: Send a blank email to php-bugs+get-113485@lists.php.net to get a copy of this message
 ID:               36797
 Updated by:       ramsey@php.net
 Reported By:      mauroi at digbang dot com
 Status:           Assigned
 Bug Type:         PDO related
 Operating System: Win XP SP2
 PHP Version:      5.1.2
 Assigned To:      wez
 New Comment:

maggie@intermaggie.com and I debugged this issue for hours, and here's
what it came down to.

We fixed this issue by doing the following:

1. As suggested, the DSN string was modified to contain
'charset=AL32UTF8'

2. Apache now has an environment variable NLS_LANG set as follows:
NLS_LANG='AMERICAN_AMERICA.AL32UTF8'

3. Make sure that $ORACLE_HOME/nls/data and all files within are
world-readable.


Previous Comments:
------------------------------------------------------------------------

[2007-06-05 19:15:39] pajoye@php.net

As information, I use  'oci:...charset=AL32UTF8' with latest IC and
oracle 10g as server and works (5.2.2 and cvs).

------------------------------------------------------------------------

[2007-06-05 18:45:56] ramsey@php.net

Note that I'm not using HTML entities in the field, but rather, actual
Japanese characters. The bug report here appears to convert these chars
to HTML entities.

------------------------------------------------------------------------

[2007-06-05 18:44:26] ramsey@php.net

Here's some more reproduce code:

<?php
$dbh = new PDO("oci:dbname=asylum;charset=UTF-8", "dev", "dev");
$dbh->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);

// Create table
$dbh->exec('create table my_test_table(my_field varchar2(100))');

// Insert data
$dbh->exec('insert into my_test_table(my_field) values (\'foo\')');
$dbh->exec('insert into my_test_table(my_field) values
(\'&#26085;&#26412;&#35486; \')');

// Get data
foreach ($dbh->query('select my_field from my_test_table') as $row) {
    var_dump($row);
}

$dbh->exec('drop table my_test_table');
?>


ACTUAL OUTPUT:

array(2) {
  ["MY_FIELD"]=>
  string(3) "foo"
  [0]=>
  string(3) "foo"
}
array(2) {
  ["MY_FIELD"]=>
  string(4) "??? "
  [0]=>
  string(4) "??? "
}


EXPECTED OUTPUT:

array(2) {
  ["MY_FIELD"]=>
  string(3) "foo"
  [0]=>
  string(3) "foo"
}
array(2) {
  ["MY_FIELD"]=>
  string(4) "&#26085;&#26412;&#35486; "
  [0]=>
  string(4) "&#26085;&#26412;&#35486; "
}

------------------------------------------------------------------------

[2007-06-05 16:23:00] ramsey@php.net

I'm also having the same problem in PHP 5.2.2. I've set
NLS_LANG=AMERICAN_AMERICA.AL32UTF8 and my PDO DSN is
oci:dbname=foo;charset=UTF-8. These don't seem to have any affect. The
characters I send to the DB through PDO_OCI are still getting converted
to ???????. The DB charset is AL32UTF8. I'm using Linux.

When I change the DSN charset to AL32UTF8, then there is no output on
the page, nor are there errors reported in the error log. PHP appears to
crash but gives no response as to why.

------------------------------------------------------------------------

[2006-03-20 15:29:43] mauroi at digbang dot com

I've tried but the same happens.
I've also tried the complete NLS_LANG (AMERICAN_AMERICA.AL32UTF8) with
no success.

Thanks!

------------------------------------------------------------------------

The remainder of the comments for this report are too long. To view
the rest of the comments, please view the bug report online at
    http://bugs.php.net/36797

-- 
Edit this bug report at http://bugs.php.net/?id=36797&edit=1


Thread (12 messages)

« previous php.bugs (#113485) next »