All MySQL statements that involve INSERT have to have all the variables/strings encased with an apostrophe. In basic terms, the correct statement would be:
PHP Code:
$db->query_write("INSERT INTO " . TABLE_PREFIX . "attachmentDownloadHistory (userid, host, attachmentid) VALUES ('$userId', '$sessionId', '$attachId')");
So basically, each variable after VALUES needs to have an apostrophe around it.
As well, you can also just use this for the queries instead of $db->, to cut down on processing time for PHP with "global:"
PHP Code:
global $vbulletin;
$vbulletin->db->query_write(whatever);