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.
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');
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])); }
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');
Php code
while ($dat = oci_fetch_row($cur)) { print_r($dat[0]); }
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!

Hot AI Tools

Undresser.AI Undress
AI-powered app for creating realistic nude photos

AI Clothes Remover
Online AI tool for removing clothes from photos.

Undress AI Tool
Undress images for free

Clothoff.io
AI clothes remover

Video Face Swap
Swap faces in any video effortlessly with our completely free AI face swap tool!

Hot Article

Hot Tools

mPDF
mPDF is a PHP library that can generate PDF files from UTF-8 encoded HTML. The original author, Ian Back, wrote mPDF to output PDF files "on the fly" from his website and handle different languages. It is slower than original scripts like HTML2FPDF and produces larger files when using Unicode fonts, but supports CSS styles etc. and has a lot of enhancements. Supports almost all languages, including RTL (Arabic and Hebrew) and CJK (Chinese, Japanese and Korean). Supports nested block-level elements (such as P, DIV),

SublimeText3 Chinese version
Chinese version, very easy to use

WebStorm Mac version
Useful JavaScript development tools

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver Mac version
Visual web development tools
