<?php

$attachments = $db->run("SELECT * FROM attachment");

$i = 1;
foreach ( $attachments as $attachment ) {
    echo "$i. Starting...<br>";
    $commentId = $db->cell("SELECT id FROM comment WHERE ssCommentId = ?", $attachment['ssCommentId']);
    echo "$i. commentId: $commentId<br>";
    $db->update('attachment', ['commentId' => $commentId], ['id' => $attachment['id']]);
    echo "$i. update attachment set commentId=$commentId where id=".$attachment['id']."<br><br>";

    $i++;
}