Home  >  Article  >  Backend Development  >  What to do if php oracle is garbled?

What to do if php oracle is garbled?

藏色散人
藏色散人Original
2020-07-25 10:10:452897browse

php Oracle garbled solution: First run "select * from V$NLS_PARAMETERS;" through PLSQL to obtain the character set of Oracle; then correctly set the character set information of the server on the client.

What to do if php oracle is garbled?

Recommended: "PHP Tutorial"

PHP Oracle Chinese garbled problem

Usually when connecting to Oracle with the default configuration, you will encounter garbled characters 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. Through PLSQL Run "select * from V$NLS_PARAMETERS;" to get the character set of oracle. The variable NLS_CHARACTERSET corresponds to the character set we need. For example, here is "WE8ISO8859P1"

The method of setting the character set is as follows:

Method 1: Set environment variables before connecting

putenv("NLS_LANG=AMERICAN_AMERICA.WE8ISO8859P1");
$conn=oci_new_connect($config['username'], $config['password'],$config['database']);

Related introduction:

Oracle General Oracle Company;

Oracle Corporation, the full name of Oracle Corporation (Oracle Software Systems Co., Ltd.), is the world's largest enterprise software company, headquartered in Redwood Beach, California, USA. Officially entered the Chinese market in 1989. In 2013, Oracle surpassed IBM and became the world's second largest software company after Microsoft.

Method 2: Set environment variables when connecting

$conn=oci_new_connect($config['username'], $config['password'],$config['database'],'we8iso8859p1');

But soon you will find that the Chinese data read through the above settings does not set the encoding It can be displayed normally, but once used in the page (if the character set of the page is UTF8), it will still be garbled.

And even if it is converted from we8iso8859p1 -> utf-8, it will still be 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 What to do if php oracle is garbled?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn