Try different odbc connect calls

不想你离开。 提交于 2019-12-13 06:25:54

问题


I would like to try to connect to a database (using odbc) where I necessarily don't know the exact password. That is, I have a couple of different alternatives what the password might be, and I want my code to figure out which one is right.

How can I do this using PHP?


回答1:


Just wrap the call to odbc_connect in a foreach loop trying all the passwords:

function my_odbc_connect($dsn, $user, array $passwords) {
    foreach ($passwords as $password) {
        $connection = odbc_connect($dsn, $user, $password);
        if (is_resource($connection)) {
            return $connection;
        }
    }
    return false;
}

and then just do

$connection = my_odbc_connect('blah', 'user', array('foo', 'bar', 'baz'));


来源:https://stackoverflow.com/questions/12061825/try-different-odbc-connect-calls

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!