ociconnect php,PHP: oci_connect - Manual

How to connect from PHP to an Oracle database using OID (Oracle Internet Directory):

OID is like a lookup index that contains connection strings for connecting to various databases. Without OID, a database connection string would be stored directly in the code settings and used by the PHP code to connect to a database. With OID, a lookup can be made to the OID LDAP to acquire the database connection string. Then the PHP code will use the acquired database connection string to connect to the database as before.

OID allows a DBA to manage/change which database server that an application uses without having to change any database settings in the PHP application itself or on the application server.

Here are the basic steps for PHP to connect to a database via OID:

- The DBA should provide you the connection information for the OID LDAP as well as the username/password for the database connection.

- Connect to the OID LDAP using the provided information

- Search for the appropriate LDAP record

- Get the connection string data from the record attribute, \"orclnetdescstring\"

- Close the LDAP connection

- Use the acquired connection string data to connect to the database as usual using the provided database username/password.

Here is basic sample code to do this:

// Get connection string from OID LDAP

$ds=ldap_connect($servername,$serverport); // Connect to ldap

$r=ldap_bind($ds); // Bind to ldap

$sr = ldap_search($ds, \"cn=OracleContext,dc=___,dc=___,dc=___\", \"cn=$sid\"); // Run query

$info = ldap_get_entries($ds, $sr); // Get entries

ldap_close($ds); // Close connection

$dbconnectstring = $info[0][\"orclnetdescstring\"][0]; // Extract db connect string from ldap search result array

// Connect to database using acquired connection string from OID

$dbconnection = oci_connect ($username,$password,$dbconnectstring);

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值