Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to set oracle Encoding with php

2025-01-17 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/03 Report--

This article mainly explains "how to use php to set up oracle coding", the content of the article is simple and clear, easy to learn and understand, now please follow the editor's ideas slowly in depth, together to study and learn "how to use php to set oracle coding" bar!

Php sets the oracle encoding method: 1, get the character set of oracle; 2, run "select * from Velocity NLSystPARAMETERS;"; 3, transform the code through the iconv function.

This article operating environment: windows7 system, PHP7.1 version, DELL G3 computer

How does php set oracle encoding?

Php connection oracle set character set to avoid garbled code

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

Looking up 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 variant NLScharacters paramenters;". 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 file uses utf-8, so the acquired code has to undergo the following transcoding:

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

Update:

Colleagues say 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 am in oci_connect, I just specify utf-8 directly, saving even the transcoding.

$C1 = oci_connect ("scott", "tiger", $db, 'UTF8')

In addition, there is a strange problem: the iconv of the previous transcoding is normal in the tester environment, but it cannot be parsed properly when it is passed remotely, and then it can be replaced by mb_convert_encoding. The code is as follows:

$nickname = mb_convert_encoding ($dat [0], 'utf-8',' gbk')

The possible reason is whether "/ / IGNORE" is added to the second parameter in iconv. Please refer to http://cn2.php.net/manual/en/function.iconv.php. If you are interested, you can try, but I won't try.

In addition, we attach a self-encapsulated php method for querying oracle data DingSql:

/ * * Encapsulation access to oracle to execute sql query * @ param sql* @ return false or string or array (array ()) * @ author xzz in the morning of May 5, 2018 9:38:54*/function DingSql ($sql =') {header ("Content-type: text/html; charset=utf-8"); if (! $sql) return false; $conn= oci_connect ('name',' passwd', 'IP:PORT/serverName','zhs16gbk') If ($conn) {$stid = oci_parse ($conn, $sql); / / configure the SQL statement, ready to execute if (! $stid) {$e = oci_error ($conn); print htmlentities ($e ['message']); exit;} $r = oci_execute ($stid, OCI_DEFAULT); / / execute SQL. OCI_DEFAULT means do not automatically commit if (! $r) {$e = oci_error ($stid); echo htmlentities ($e ['message']); exit;} $kkk = []; $I ='-1' While ($row = oci_fetch_array ($stid, OCI_ASSOC+OCI_RETURN_NULLS)) {/ / return the associated data and create null $iConstructions; foreach ($row as $key = > $item) {$kkk [$I] [$key] = iconv ("gb2312", "utf-8//TRANSLIT", $item);} oci_close ($conn); return $kkk / / 2D associative array} else {echo 'failed to connect to oracle!' ; exit;}} Thank you for reading, the above is the content of "how to set up oracle coding with php". After the study of this article, I believe you have a deeper understanding of how to set up oracle coding with php, and the specific use needs to be verified in practice. Here is, the editor will push for you more related knowledge points of the article, welcome to follow!

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.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report