如何在PHP中捕获oracle宽限期消息?

发布于 2024-11-03 03:31:49 字数 290 浏览 6 评论 0原文

我在 PHP 应用程序中使用 Oracle 数据库。

用户尝试连接到 PHP 应用程序。他的密码已过期,但其用户个人资料的宽限期不为空,因此他仍然可以连接到应用程序。

我想做的是认识到该用户应该更改他的密码并向他显示一条消息。

我尝试过使用 oci_error(),但它没有返回任何内容,因为使用该用户连接到数据库没有失败。

我想捕获 ORA-28001 (和 ORA-28002)

不幸的是,我无法对数据库本身的结构进行任何更改(添加额外的表或额外的字段)。

I use an Oracle database in a PHP application.

A user tries to connect to the PHP application. His password has expired, but the grace period for his user's profile isn't null, so he can still connect to the application.

What I would like to do is recognize that this user should change his password and display him a message.

I've tried with oci_error(), but it doesn't return anything as there were no failure in connecting to the database with this user.

I would like to catch ORA-28001 (and ORA-28002)

Unfortunately, I can't do any change of structure in the database itself (add extra table or extra field).

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(3

锦爱 2024-11-10 03:31:49

扩展 Narf 的答案,这对我来说适用于 Oracle 11.2

<?php

function my_error_handler($errno, $errstr, $errfile, $errline) {
    if (preg_match('/ORA-28002: [ a-zA-Z]*([0-9])+/', $errstr, $matches)) {
        echo "Your password will expire within ${matches[1]} days\n";
    }
}

set_error_handler("my_error_handler", E_WARNING);

$c = @oci_connect("hr", "welcome", "localhost/XE");
if (!$c) {
    $m = oci_error();
    echo "Connection failed: " . $m['message'] . "\n";
} else {
    echo "Connected OK\n";
    // Prove the connection is valid
    $s = oci_parse($c, "select 'Query is OK' as c from dual");
    oci_execute($s);
    $r = oci_fetch_array($s, OCI_ASSOC);
    echo $r['C'] . "\n";
}

restore_error_handler();

?>

宽限期内密码的输出是:

Your password will expire within 1 days
Connected OK
Query is OK

Expanding Narf's answer, this works for me with Oracle 11.2

<?php

function my_error_handler($errno, $errstr, $errfile, $errline) {
    if (preg_match('/ORA-28002: [ a-zA-Z]*([0-9])+/', $errstr, $matches)) {
        echo "Your password will expire within ${matches[1]} days\n";
    }
}

set_error_handler("my_error_handler", E_WARNING);

$c = @oci_connect("hr", "welcome", "localhost/XE");
if (!$c) {
    $m = oci_error();
    echo "Connection failed: " . $m['message'] . "\n";
} else {
    echo "Connected OK\n";
    // Prove the connection is valid
    $s = oci_parse($c, "select 'Query is OK' as c from dual");
    oci_execute($s);
    $r = oci_fetch_array($s, OCI_ASSOC);
    echo $r['C'] . "\n";
}

restore_error_handler();

?>

Its output for a password in the grace period is:

Your password will expire within 1 days
Connected OK
Query is OK
顾北清歌寒 2024-11-10 03:31:49

请参阅 OCILogon 问题 - Oracle 密码过期非常相似的问题,有解决方案。应该可以在当前的 php 版本中工作。也非常类似于 宽限期内的 OCILogon - ORA-28002on SO

See OCILogon problem - Oracle password expiry a very similar problem, with a solution. Should work in the current php version. Also very similar to OCILogon during Grace Period - ORA-28002on SO

流殇 2024-11-10 03:31:49

尝试在执行 oci_connect() 时启用警告,然后使用自定义错误处理程序捕获它们(确保在连接时不会忽略带有 @ 的错误)。这可能需要您还调整 php.ini 中的 oci 扩展设置。

Try enabling warnings when you execute oci_connect() and then catching them with a custom error handler(make sure you're not ignoring errors with @ when connecting). This could require you to tweak also the oci extension settings in php.ini.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文