Can anyone see what I'm doing wrong here? I'm getting:
SQLSTATE[42000]: Syntax error or access violation: 1064 You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'INSERT INTO userDevice (userID, deviceID, deviceName, deviceOS, deviceOSVersion,' at line 1
It was working fine when I used seperate parameters for the INSERT & the UPDATE but I swapped to user vars to cut the number of bound parameters..
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;
}
}