当前位置:网站首页 > 杂货铺 > 正文

php pdo oracle中文乱码的快速解决方法

评论:0 发布时间: 2021-06-03 浏览: 71

先查一下oracle的编码  :

SELECT * FROM NLS_DATABASE_PARAMETERS

 

 

在/etc/profile.d/简历oracle.sh

内容如下在NLS_LANG设置编码


ORACLE_HOME=/usr/lib/oracle/12.1/client64

C_INCLUDE_PATH=/usr/include/oracle/12.1/client64

LD_LIBRARY_PATH=$ORACLE_HOME/lib

#remember this is the client NLS_LANG not the server one

NLS_LANG=FRENCH_FRANCE.UTF8 

export ORACLE_HOME LD_LIBRARY_PATH NLS_LANG

然后修改 /etc/init.d/php-fpm

在头部增加


. /etc/profile.d/oracle.sh
 
. /etc/init.d/functions
. /etc/profile.d/oracle.sh
# Check that networking is up.
. /etc/sysconfig/network
# Additional environment file
if [ -f /etc/sysconfig/php-fpm ]; then
. /etc/sysconfig/php-fpm
fi
if [ "$NETWORKING" = "no" ]
then
exit 0
fi
RETVAL=0
prog="php-fpm"
pidfile=${PIDFILE-/var/run/php-fpm/php-fpm.pid}
lockfile=${LOCKFILE-/var/lock/subsys/php-fpm}


然后重新启动php即可

有的机器上找不到 php-fpm  (lanmp环境)

 

折中方法  亲测可用

1、在  /etc/profile.d 下新建oracle.sh

内容如下 :

ORACLE_HOME=/usr/lib/oracle/12.2/client64
C_INCLUDE_PATH=/usr/include/oracle/12.2/client64
LD_LIBRARY_PATH=$ORACLE_HOME/lib
#remember this is the client NLS_LANG not the server one
NLS_LANG=AMERICAN_AMERICA.AL32UTF8
export ORACLE_HOME LD_LIBRARY_PATH NLS_LANG

service httpd restart

2、在etc/rc.local文件中添加

/etc/profile.d/oracle.sh





其实就是:

export ORACLE_HOME=/usr/lib/oracle/12.2/client64
export C_INCLUDE_PATH=/usr/include/oracle/12.2/client64
export LD_LIBRARY_PATH=$ORACLE_HOME/lib 

export NLS_LANG=AMERICAN_AMERICA.UTF8


在php中则是

 


 //putenv("LD_LIBRARY_PATH=/usr/lib/oracle/12.2/client64/lib");

//putenv("ORACLE_HOME=/usr/lib/oracle/12.2/client64");

注意不要重复指定


putenv("NLS_LANG=AMERICAN_AMERICA.AL32UTF8");


 

TAGS:

Powered By Csuper,Theme By Csuper 悠然小屋,Copyright Csuper All Rights Reserved. 湘ICP备18017694 网络是工具,不是玩具 QQ:493754678