为什么不需要数据库凭证工作?

时间:2016-01-18 14:00:35

标签: php mysqli

我有一个连接数据库的功能。如果我硬编码数据库凭据,该函数将起作用。但是,如果我使用require或include数据库凭据,它将无法正常工作,我会收到连接错误。我可以通过函数中的include和require文件回显凭据。

class mysql{

    function verifyUser($un,$pwd){
        include 'cat.inc.php';

        $conn = mysqli_connect($host,$user,$pwd,$db) or die("This is an error connecting".mysql_error());

        $sql = 'select salt,pwd,hospital_id, fname,lname,client_id,employee from client where email = ?';

        if($stmt = $conn->prepare($sql)){

            $stmt->bind_param('s', $un);
            $stmt->bind_result($salt,$storedPwd,$hospital_id,$fname, $lname,$client_id,$employee);
            $stmt->execute();
            $stmt->fetch();

            if (sha1($pwd.$salt)==$storedPwd){

                $_SESSION['clientID'] = $client_id;
                $_SESSION['hospitalID'] =$hospital_id;
                $_SESSION['client_fn'] = $fname;
                $_SESSION['client_ln']=$lname;
                $_SESSION['employee']=$employee;    
                $_SESSION['start']=time();  
                return true;

                }else{
                return false;
            }

        }
    }
}

0 个答案:

没有答案