尝试不同的 odbc 连接调用 [英] Try different odbc connect calls
本文介绍了尝试不同的 odbc 连接调用的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我想尝试连接到我不一定知道确切密码的数据库(使用 odbc).也就是说,我有几种不同的密码可能是什么,我希望我的代码确定哪个是正确的.
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.
如何使用 PHP 执行此操作?
How can I do this using PHP?
推荐答案
只需在尝试所有密码的 foreach 循环中包装对 odbc_connect
的调用:
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;
}
然后就去做
$connection = my_odbc_connect('blah', 'user', array('foo', 'bar', 'baz'));
这篇关于尝试不同的 odbc 连接调用的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文