PHP连接ORACLE时乱码,手动PUTENV(NLS_LANG)环境变量后正常!
我有一个项目,从MYSQL迁移到ORACLE RAC中,数据库为UTF8编码格式,用PHP进行简单连接取出的中文均为问号,百度后发现在进行数据库连接时需要指定连接编码为UTF8,我指定了环境变量,并在测试页打印了PHP中全局环境变量,phpinfo(INFO_ENVIRONMENT),结果就正常了。如果不指定,PHP环境变量页面没显示nls_lang的变量信息,则依旧乱码,现在有什么办法,我有好几十个PHP页面,难道都要手动在开头PUTENV(NLS_LANG)定义一下么。求高手赐招能够在PHP服务运行时就自带环境变量nls_lang的参数。并自动在INFO_ENVIRONMENT显示成功。
补充下,我是centos6.5,已经在.bash_profile中定义了nls_lang。但貌似不起作用。PHP是5.6,WEB服务器是nginx 1.9
回复讨论(解决方案)
ORACLE 没有 utf8 只有 utf-8
你在链接 ORACLE 时就应声明所用字符集
只有 ORACLE 8 及以下,才需要设置环境变量
ORACLE 没有 utf8 只有 utf-8
你在链接 ORACLE 时就应声明所用字符集
只有 ORACLE 8 及以下,才需要设置环境变量
您说的对,但是有没有办法设置默认字符集,即和JAVA那样不在PHP连接字符串中
$conn = OCI_Logon('orcl','orcl','127.0.0.1/orcl','UTF8');或者putenv("NLS_LANG=american_america,UTF8");
两者都能够正常。我现在就是想和JAVA那样不用事先申明,因为我的TEST.PHP文本就是UTF8格式,数据库也是UTF8格式,应该能够自动匹配吧?
我手动输出系统环境变量nls_lang,结果是空的,
phpinfo(INFO_ENVIRONMENT);
?>
求赐教如何才能在PHP初始化的时候装载系统环境变量,换句话说如何指定PHP的环境变量,bash_profile不起作用。
写成 $conn = OCI_Logon('orcl','orcl','127.0.0.1/orcl','UTF8'); 就那么费事吗?
java 是通过 jdbc 进行数据库操作的,php 是通过客户端的
所以后者要多做一些设置上的事情
额,其实这公司是别的软件公司的产品,原生MYSQL,后来由于公司要求统一用ORACLE RAC数据库,迁移过去的。。好吧我找找他们的数据库连接是写在哪的,自己改下算了。

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

AI Hentai Generator
Generate AI Hentai for free.

Hot Article

Hot Tools

Notepad++7.3.1
Easy-to-use and free code editor

SublimeText3 Chinese version
Chinese version, very easy to use

Zend Studio 13.0.1
Powerful PHP integrated development environment

Dreamweaver CS6
Visual web development tools

SublimeText3 Mac version
God-level code editing software (SublimeText3)

Hot Topics



Laravel simplifies handling temporary session data using its intuitive flash methods. This is perfect for displaying brief messages, alerts, or notifications within your application. Data persists only for the subsequent request by default: $request-

The PHP Client URL (cURL) extension is a powerful tool for developers, enabling seamless interaction with remote servers and REST APIs. By leveraging libcurl, a well-respected multi-protocol file transfer library, PHP cURL facilitates efficient execution of various network protocols, including HTTP, HTTPS, and FTP. This extension offers granular control over HTTP requests, supports multiple concurrent operations, and provides built-in security features.

Laravel provides concise HTTP response simulation syntax, simplifying HTTP interaction testing. This approach significantly reduces code redundancy while making your test simulation more intuitive. The basic implementation provides a variety of response type shortcuts: use Illuminate\Support\Facades\Http; Http::fake([ 'google.com' => 'Hello World', 'github.com' => ['foo' => 'bar'], 'forge.laravel.com' =>

Alipay PHP...

Do you want to provide real-time, instant solutions to your customers' most pressing problems? Live chat lets you have real-time conversations with customers and resolve their problems instantly. It allows you to provide faster service to your custom

Article discusses late static binding (LSB) in PHP, introduced in PHP 5.3, allowing runtime resolution of static method calls for more flexible inheritance.Main issue: LSB vs. traditional polymorphism; LSB's practical applications and potential perfo

The article discusses adding custom functionality to frameworks, focusing on understanding architecture, identifying extension points, and best practices for integration and debugging.

Article discusses essential security features in frameworks to protect against vulnerabilities, including input validation, authentication, and regular updates.
