In addition to Weibo, there is also WeChat
Please pay attention
WeChat public account
Shulou
2025-04-06 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >
Share
Shulou(Shulou.com)06/02 Report--
This article mainly explains "how to solve the problem of php connection oracle garbled", interested friends may wish to have a look. The method introduced in this paper is simple, fast and practical. Next let the editor to take you to learn "how to solve the problem of php connection oracle garbled"!
Php connection oracle garbled solution: 1, set environment variables; 2, access to the oracle character set; 3, through the "iconv ('GBK','utf-8',$vo [" USERNAME "]);" method conversion can be.
This article operating environment: Windows7 system, PHP7.1 version, DELL G3 computer
How to solve the problem of garbled code in php connection oracle?
Notes on PHP connection Oracle and garbled problem
1. PHP connects to Oracle
Step 1. Extract Oracle Instant Client core DLL
Download the Instant Client Basic (11g) package for Windows from the Instant Client page of OTN. The size of this compressed file is approximately 48MB. Create a subdirectory (for example, c:\ instantclient11_2) and copy the following libraries from the compressed file to the apache\ bin directory:
Oraociei11.dll orannzsbb11.dll oci.dll
The total size of these three files is about 126MB.
To use the "oracle" extension of the older version of PHP (enabled with "extension=php_oracle.dll" in php.ini), copy ociw32.dll instead of oci.dll.
Step 2: edit the environment variable to add c:\ instantclient11_2 to the PATH (the system environment variable precedes other Oracle directories).
For example, on Win7, click computer-> right-click Properties-> Advanced system Settings-> Advanced-> Environment variables, and edit PATH in the list of system variables.
If the tnsnames.ora file is used to define the Oracle Net service name, copy the tnsnames.ora to c:\ instantclient11_2 and set the user environment variable TNS_ADMIN to c:\ instantclient11_2.
Step 3: open the oci8 extension of php to edit php.ini, and open the OCI8 extension, that is, remove the comment symbol';': extension=php_oci8.dll
Restart Apache. Restart the server (the server must be restarted, otherwise the environment variables will not work)
If you see the following via phpinfo () after restart, the configuration is successful:
Oci8OCI8 SupportenabledVersion1.4.7Revision$Id: bf2eaf558b050b6d2e6d098bed6345af7e842ea4 $Active Persistent Connections0Active Connections0Oracle Run-time Client Library Version11.2.0.3.0Oracle Instant Client Version11.2Temporary Lob supportenabledCollections supportenabledDirectiveLocal ValueMaster Valueoci8.connection_classno valueno valueoci8.default_prefetch100100oci8.eventsOffOffoci8.max_persistent-1-1oci8.old_oci_close_semanticsOffOffoci8.persistent_timeout-1-1oci8.ping_interval6060oci8.privileged_connectOffOffoci8.statement_cache_size2020
2. PHP Oracle Chinese garbled problem
Usually, the default configuration connection Oracle will encounter garbled code problems when dealing with Chinese. In fact, most people know that before the client connects to the Oracle server, it is necessary to correctly set the server character set information on the client side. Run "select * from variant NLSystPARAMETS;" through PLSQL to obtain the oracle character set. The variable NLS_CHARACTERSET corresponds to the character set we need. For example, here is "WE8ISO8859P1".
You can set the character set 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'])
Method 2: set environment variables when connecting
$conn=oci_new_connect ($config ['username'], $config [' password'], $config ['database'],' we8iso8859p1')
But you will soon find that the Chinese data read through the above settings can be displayed normally without setting the encoding, but it will still be garbled once used in the page (if the character set of the page is UTF8).
And even if you do the conversion from we8iso8859p1-> utf-8 is still garbled.
In fact, after careful study, it is found that oci8 uses database encoding WE8ISO8859P1 to obtain data and then automatically converts it to the default encoding format of the operating system. If the default encoding of the operating system I use is GBK, in fact, after reading through OCI8, the character encoding is GBK. Therefore, when the page is used, the encoding conversion should be from GBK-> utf-8:
Echo iconv ('GBK','utf-8',$vo ["USERNAME"]); at this point, I believe you have a deeper understanding of "how to solve the problem of php connection oracle garbled". You might as well do it in practice! Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!
Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.
Views: 0
*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.
Continue with the installation of the previous hadoop.First, install zookooper1. Decompress zookoope
"Every 5-10 years, there's a rare product, a really special, very unusual product that's the most un
© 2024 shulou.com SLNews company. All rights reserved.