想象输出图像不在数据库中更新

I retrieve image data from my database, use Imagick to manipulate it and then I write the output back to the database. The image is changed fine (in this case rotated) but it doesn't write back the changed image. Instead it writes back the original image.

$sql = "SELECT photoData FROM tblPhotos WHERE photoID = '..someID..';";
$res = mysqli_query($connect, $sql);

while($row = mysqli_fetch_array($res)) {
    $imagedata = $row['photoData'];
}

$im = new Imagick();
$im->readimageblob($imagedata);
$angle = 90;
$im->rotateimage("#FFF", $angle);
$output = $im->getimageblob();

$sql = "UPDATE tblPhotos SET photoData= '" . $output . "' WHERE photoID = '..someID..';";
mysqli_query($connect, $sql);

If I change the UPDATE $sql to:

$sql = "UPDATE tblPhotos SET photoData= 'abc' WHERE photoID = '..someID..';";

then I can see the UPDATE back to the database is working, so that is not the issue. What am I missing here?