php 持久连接,PHP 使用一个持久连接连到 Oracle 数据库

当使用 oci_pconnect 连接到 Oracle 数据库时,如果会话已登出但连接仍有效,可能会遇到 'ORA-01012: not logged on' 错误。即使尝试关闭连接,问题依然存在。为解决此问题,该段代码展示了如何通过连续尝试 oci_pconnect、oci_connect 和 oci_new_connect 来确保建立有效的持久连接。
摘要由CSDN通过智能技术生成

[Editor's note: OCI8 1.3 should not experience the problem described in this user comment. The first use of such a connection will return an Oracle error which will trigger a cleanup in PHP.  Subsequent persistent connection calls will then succeed.  For high availability you might consider doing consecutive oci_pconnect calls in your script.]

If you connect using oci_pconnect and the connection has logged you off but is still valid, there seems to be no way to re-use that connection. The next time I try oci_pconnect and then perform an oci_execute operation, I get a "ORA-01012: not logged on" warning. This problem remains, even if I close the connection using oci_close. I ended up with the following (rather annoying) code.

{

if (!function_exists('oci_pconnect'))

returnfalse;$toReturn=oci_pconnect('user','pass','db');

if ($testRes= @oci_parse($toReturn,'SELECT Count(group_type_code) FROM pvo.group_type'))

if (@oci_execute($testRes))

if (@oci_fetch_array($testRes))

return$toReturn;oci_close($toReturn);

if (!function_exists('oci_connect'))

returnfalse;$toReturn=oci_connect('user','pass','db');

if ($testRes= @oci_parse($toReturn,'SELECT Count(group_type_code) FROM pvo.group_type'))

if (@oci_execute($testRes))

if (@oci_fetch_array($testRes))

return$toReturn;oci_close($toReturn);

if (!function_exists('oci_new_connect'))

returnfalse;$toReturn=oci_new_connect('user','pass','db');

if ($testRes= @oci_parse($toReturn,'SELECT Count(group_type_code) FROM pvo.group_type'))

if (@oci_execute($testRes))

if (@oci_fetch_array($testRes))

return$toReturn;oci_close($toReturn);

returnfalse;

}?>

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值