win2003 php oracle,Windows2003 + PHP5.4.7 + Apache2.2.15 + Oracle9.0

Oracle数据库与Web服务器分布在两台机器上。

Web端的配置:

下载 oracle instant client:instantclient_10_2,存放路径:D:\oracle_instantclient\instantclient_10_2

Windows 的系统 Path 变量前加:D:\oracle_instantclient\instantclient_10_2 路径。

php.ini 中打开 oci 开关:

extension=php_oci8.dll      ; Use with Oracle 10gR2 Instant Client

extension=php_pdo_oci.dll

重新启动 Apache 服务。这时,可以在 phpinfo 信息里看到 oci8 已经加载成功。?

但是,运行PHP的测试代码,oci_connect()函数报错:

oci_connect(): ORA-12154: TNS:could not resolve the connect identifier specified in ...

pdo_oci报错:

SQLSTATE[42S02]: pdo_oci_handle_factory: ORA-12154: TNS:could not resolve the connect identifier specified (ext\pdo_oci\oci_driver.c:631)

解决:

建立系统环境变量:

TNS_ADMIN = D:\oracle_instantclient\instantclient_10_2

NLS_LANG = AMERICAN_AMERICA.UTF8

重新启动 Apache 服务。

同时,需要 tnsnames.ora 网络配置文件(位于D:\oracle_instantclient\instantclient_10_2下),用于PHP去解析SERVICE_NAME,例如:

# TNSNAMES.ORA Network Configuration File

tns1 =

(DESCRIPTION=

(ADDRESS_LIST =

(ADDRESS = (PROTOCOL=TCP)(HOST = 10.0.0.90)(PORT = 1521))

)

(CONNECT_DATA=

(SERVICE_NAME=mydb90)

)

)

更改 tnsnames.ora 文件,需要重新启动 Apache 服务,从而让 PHP 识别新的 tnsnames.ora 配置。

PHP 的 oci 连接示例:$conn=oci_connect("scott", "tiger", "tns1")。

以上是 PHP 作为 Oracle 客户端,必须做的。

Navicat8.2 for Oracle 作为 Oracle 管理客户端,只要配置 oci 指向 D:\oracle_instantclient\instantclient_10_2\oci.dll,即可连接到 Oracle 数据库服务器。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值