Reputation: 559
Here is my php codes
$tns = "
(DESCRIPTION =
(ADDRESS_LIST =
(ADDRESS = (PROTOCOL = TCP)(HOST = localhost)(PORT = 1521))
)
(CONNECT_DATA =
(SERVICE_NAME = myservice)
)
)";
$conn = new PDO("oci:dbname=" . $tns, 'user', 'pass');
When I try to set the charset to UTF8 like this:
$conn = new PDO("oci:dbname=" . $tns . ";charset=UTF8", 'user', 'pass');
will get:
ERROR: SQLSTATE[HY000]: OCINlsCharSetNameToId: unknown character set name (/app/software/php-5.6.30/ext/pdo_oci/oci_driver.c:610)pdo is NULL
I have already set the NLS_LANG to AMERICAN_AMERICA.UTF8
, but looks like my host machine need to restart, I can NOT do it now.
So, what should I do can change the charset to utf8 with pdo/oci connected to oracle database??
And I want:
Upvotes: 2
Views: 5823
Reputation: 559
Takes me 4 hours to solve this:
/etc/sysconfig/httpd
file by command vim /etc/sysconfig/httpd
Add the codes below at the end of this file
export LD_LIBRARY_PATH=/app/oracle/orahome/lib
export ORACLE_HOME=/app/oracle/orahome
export NLS_LANG=AMERICAN_AMERICA.UTF8
service httpd restart
You have to do NOTHING about your pdo
or oracle
or host machine
.
If you don't know the variable's value, just echo $ORACLE_HOME
in command line.
BTW,
All these three variables should be set in /ect/profile
, and you'd better make them same in these two files.
Upvotes: 3