任何人都可以看到这个PHP PDO语句有什么问题

时间:2018-05-17 09:44:41

标签: php mysql pdo

有谁能看到我在这里做错了什么?我得到了:

SQLSTATE [42000]:语法错误或访问冲突:1064 SQL语法中有错误;查看与您的MySQL服务器版本相对应的手册,以便在' INSERT INTO userDevice(userID,deviceID,deviceName,deviceOS,deviceOSVersion,'第1行)附近使用正确的语法

当我使用INSERT& amp;的单独参数时工作正常。 UPDATE但我交换到用户变量以减少绑定参数的数量..

private function saveDeviceData($userID,$deviceID,$deviceName,$deviceOS,$deviceOSVersion)
    {
    $sql = "SET @did = :did, @dname = :dname, @dos = :dos, @dver = :dver;";
    $sql .= "INSERT INTO userDevice (userID, deviceID, deviceName, deviceOS, deviceOSVersion, timestamp) VALUES(:uid, @did, @dname, @dos, @dver, NOW())";
    $sql .= " ON DUPLICATE KEY UPDATE deviceID = @did, deviceName = @dname, deviceOS = @dos, deviceOSVersion = @dver, timestamp = NOW()";
    try {
        $ps = $this->db->prepareStatement($sql);
        $ps->bindParam(":uid",$userID, PDO::PARAM_INT);
        $ps->bindParam(":did",$deviceID, PDO::PARAM_STR);
        $ps->bindParam(":dname",$deviceName, PDO::PARAM_STR);
        $ps->bindParam(":dos",$deviceOS, PDO::PARAM_STR);
        $ps->bindParam(":dver",$deviceOSVersion, PDO::PARAM_STR);
        $ps->execute();
        return TRUE;
        }
    catch (PDOException $e)
        {
        $this->error("PDO Error: ".$e->getMessage());
        $this->validationError($this->kInvalidEmailOrPasswordMessage);
        return FALSE;
        }
    }

0 个答案:

没有答案