Try different odbc connect calls

2019-09-05 08:49发布

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?

标签: php odbc
1条回答
劫难
2楼-- · 2019-09-05 09:17

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'));
查看更多
登录 后发表回答