来自sso服务器的输入数据未插入mysql数据库

时间:2019-07-11 11:58:13

标签: php mysql sql debugging mysqli

从SSO服务器检索的数据未插入我的数据库中。突然,它停止工作,并且一个代码字也没有更改。以前,数据曾经被正确地插入数据库中。不知道确切的问题是什么。但是我想可能与更新语言有关。

我还验证了来自sso服务器的userdata即将到来。是的,当我回显时,来自sso服务器的数据就会到来。数据也正在更新(如果以前的用户在此处更改了个人资料),但是inserrt查询无法正常工作。另外,当我使用Mysqli命令时,它们不起作用。

        <?php
    class User {
          private $dbHost     = "";
          private $dbUsername = "";
private $dbPassword = "";
private $dbName     = "";
private $userTbl    = 'database table';


function __construct(){
    if(!isset($this->db)){
        // Connect to the database
        $conn = new mysqli($this->dbHost, $this->dbUsername, $this->dbPassword, $this->dbName);
        if($conn->connect_error){
            die("Failed to connect with MySQL: " . $conn->connect_error);
        }else{
            $this->db = $conn;
        }
    }
}

function checkUser($userData = array()){
    if(!empty($userData)){
        // Check whether user data already exists in database
        $prevQuery = "SELECT * FROM ".$this->userTbl." WHERE username = '".$userData['username']."'";
        $prevResult = $this->db->query($prevQuery);


        if($prevResult->num_rows > 0){
            // Update user data if already exists
            $query = "UPDATE ".$this->userTbl." SET first_name = '".$userData['first_name']."', last_name = '".$userData['last_name']."', email = '".$userData['email']."', roll = '".$userData['roll']."',hostel = '".$userData['hostel']."',mobile = '".$userData['mobile']."', sex = '".$userData['sex']."',  picture = '".$userData['picture']."'WHERE username = '".$userData['username']."'";
            $update = $this->db->query($query);

        }else{
            // Insert user data
            $query = "INSERT INTO ".$this->userTbl." SET username = '".$userData['username']."', first_name = '".$userData['first_name']."', last_name = '".$userData['last_name']."', email = '".$userData['email']."', roll = '".$userData['roll']."',hostel = '".$userData['hostel']."',mobile = '".$userData['mobile']."', sex = '".$userData['sex']."',  picture = '".$userData['picture']."'";
            $insert = $this->db->query($query);
        }



        // Get user data from the database
        $result = $this->db->query($prevQuery);
        $userData = $result->fetch_asso`c();
    }

    // Return user data
    return $userData;
}

} ?>

0 个答案:

没有答案