Home > Backend Development > PHP Problem > What should I do if the php connection to Oracle is garbled?

What should I do if the php connection to Oracle is garbled?

藏色散人
Release: 2023-03-17 06:46:02
Original
2149 people have browsed it

Solution to the garbled code in PHP connection to Oracle: 1. Get the character set of Oracle by running the "select * from V$NLS_PARAMETERS;" command; 2. Modify the variable "NLS_CHARACTERSET" to the corresponding character set; 3. Just set the local PHP files to utf-8.

What should I do if the php connection to Oracle is garbled?

The operating environment of this tutorial: Windows 7 system, PHP version 8.1, Dell G3 computer.

What should I do if the php connection to oracle is garbled?

php connects to oracle to set the character set to avoid garbled characters

The database uses oracle. When php connects to oracle, it is best to specify the character set.

Check the PHP manual. The fourth parameter of oci_connect is charset, which is the key.

First get the character set of oracle and run "select * from V$NLS_PARAMETERS;". The variable NLS_CHARACTERSET corresponds to the character set we need. For example, here is "ZHS16GBK".

So, the final PHP code is:

$c1 = oci_connect("scott", "tiger", $db, 'zhs16gbk');
Copy after login

My local PHP files use utf-8, so the obtained code needs to be converted as follows:

while ($dat = oci_fetch_row($cur)) {    print_r(iconv('gb2312', 'utf-8', $dat[0]));  }
Copy after login

Update:

Colleagues said that Oracle can provide data according to the character set specified by the client. In other words, if my local PHP file uses UTF-8, then when I use oci_connect, I can directly specify utf-8, and even the encoding conversion will be saved.

$c1 = oci_connect("scott", "tiger", $db, 'UTF8');
Copy after login

Php code

while ($dat = oci_fetch_row($cur)) {    print_r($dat[0]);  }
Copy after login

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of What should I do if the php connection to Oracle is garbled?. For more information, please follow other related articles on the PHP Chinese website!

Related labels:
source:php.cn
Statement of this Website
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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template