php oci oracle,PHP - Manual: oci_pconnect (官方文档)

当使用 oci_pconnect 连接到 Oracle 数据库时,如果会话已失效但连接仍然有效,会导致 ORA-01012 错误。此问题即使关闭连接也无法解决。为解决这个问题,文中提供了检查并重新尝试连接的代码示例,依次尝试 oci_pconnect、oci_connect 和 oci_new_connect 函数,通过执行简单的 SQL 查询来验证连接有效性。
摘要由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;

}?>

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值