使用Oracle Wallet从PHP连接到Oracle DB [英] Connect from PHP to an Oracle DB using an Oracle Wallet
问题描述
是否可以配置PHP以使用 http://download.oracle.com/docs/cd/B19306_01/network.102/b14266/cnctslsh.htm ?
Is it possible to configure PHP to use a secure external password store as described in http://download.oracle.com/docs/cd/B19306_01/network.102/b14266/cnctslsh.htm?
推荐答案
是的,您需要:
1-创建一个钱包(如您的链接所述)
2-使用Apache + PHP将Oracle Instant Client和钱夹文件放在服务器上的某个位置(例如/opt/instantclient和/opt/wallet)
3-使用以下变量启动Apache:
Yes it's possible, you need to:
1 - create a wallet (as explained in your link)
2 - put the Oracle instant client and the wallet files somewhere on the server with Apache+PHP (for example /opt/instantclient and /opt/wallet)
3 - start Apache with the following variables:
ORACLE_HOME=/opt/instantclient
LD_LIBRARY_PATH=/opt/instantclient
TNS_ADMIN=/opt/wallet
4-在/opt/wallet中,创建具有以下内容的tnsnames.ora文件:
4 - In /opt/wallet create a tnsnames.ora files with this content:
WALLET_NAME =
(DESCRIPTION =
(ADDRESS = (PROTOCOL = TCP)(HOST = DB_IP)(PORT = DB_PORT))
(CONNECT_DATA = (SID = DB_SID))
)
其中WALLET_NAME是创建钱包时选择的钱包名称,DB_IP是数据库ip地址或主机名,DB_PORT是数据库端口,DB_SID是数据库的sid.
5-在/opt/wallet中,创建具有以下内容的sqlnet.ora文件:
where WALLET_NAME it's the name of the wallet chosen when the wallet has been created, DB_IP it's the database ip address or hostname, DB_PORT it's the db port, and DB_SID it's the sid of the database
5 - In /opt/wallet create a sqlnet.ora files with this content:
WALLET_LOCATION =
(SOURCE =
(METHOD = FILE)
(METHOD_DATA =
(DIRECTORY = /opt/wallet)
)
)
SQLNET.WALLET_OVERRIDE = TRUE
6-重新启动Apache
6 - restart Apache
现在在PHP代码方面,您可以连接到数据库,并使用以下代码打开连接:
On the PHP code side now you can connect to the database opening a connection with the following code:
$conn = oci_connect("/", "", "WALLET_NAME", null, OCI_CRED_EXT);
您可以使用oci_pconnect进行持久连接,并使用相同的语法
我希望这会有所帮助,并且我不会忘记任何事情
you can use otherwise the oci_pconnect, for persistent connections, and the same syntax
I hope this helps and i didn't forget anything
这篇关于使用Oracle Wallet从PHP连接到Oracle DB的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!