PHP 通过参数传递加密密码


PHP passing encrypted password by parameter

我在函数的参数中传递加密密码以连接到数据库,但我不知道如何使用它连接到数据库?

function get_connectivity($pwd){    
    $host = "localhost";
    $user = "root";
    $pass = $pwd;
    $database = "testing";
    $db = new mysqli($host, $user, $pass, $database);
    if ($db->connect_errno) {
        return false;
        exit();
    }   
    $db->close();
    return true;
}

我这样称呼它:

get_connectivity(sha1("example"));

这可能吗?谢谢。

改成这个。它已经声明了,只需将其传递给连接即可。

function get_connectivity($pwd){    
    $host = "localhost";
    $user = "root";
    $database = "testing";
    $db = new mysqli($host, $user, $pwd, $database);
    if ($db->connect_errno) {
        return false;
        exit();
    }   
    $db->close();
    return true;
}