Question

I pass encrypted password in the parameters of a function to connect to a database, but I don't know how to use it to connect to database?

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;
}

I call it this way:

get_connectivity(sha1("example"));

Is this even possible? Thanks.

Was it helpful?

Solution

Change to this. It is already declared, just pass it to the connection.

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;
}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top