Home >Backend Development >PHP Problem >How to solve php oracle garbled problem
php Oracle garbled characters are caused by the incorrect configuration of character set information. The solution is to run "select * from V$NLS_PARAMETERS;" through PLSQL to obtain the Oracle character set and reset the correct character set. That’s it.
PHP Oracle Chinese garbled code problem
Usually the default configuration will encounter garbled code problems when connecting to Oracle when processing Chinese. , in fact, most people know that before the client connects to the Oracle server, the character set information of the server must be correctly set on the client first, and the Oracle character set can be obtained by running "select * from V$NLS_PARAMETERS;" through PLSQL. The variable NLS_CHARACTERSET corresponds to the character set we need. For example, here is "WE8ISO8859P1"
Recommended: "PHP Tutorial"
The method of setting the character set is as follows:
Method one: Set environment variables before connecting
putenv("NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1"); $conn=oci_new_connect($config['username'], $config['password'],$config['database']);
Method two: Set environment variables when connecting
$conn=oci_new_connect($config['username'], $config['password'],$config['database'],'we8iso8859p1');
But it’s fast You will find that the Chinese data read through the above settings can be displayed normally without setting the encoding, but once used in the page (if the character set of the page is UTF8), it will still be garbled,
and even if After converting from we8iso8859p1 -> utf-8, it is still garbled.
In fact, after careful study, I found that oci8 automatically converts the data to the default encoding format of the operating system after obtaining the data with the database encoding WE8ISO8859P1. If the default encoding of the operating system I use is GBK, it will actually be read through OCI8. , the character encoding is GBK, so when using the page, the encoding conversion should be from GBK -> utf-8:
echo iconv('GBK','utf-8',$vo["USERNAME"]);
The above is the detailed content of How to solve php oracle garbled problem. For more information, please follow other related articles on the PHP Chinese website!