WordPress can’t get image url but both the attachment and the actual file are there

Not sure how you’re using it, but wp_get_attachment_image_src() returns an array. This should work:

<?php
      $attachmentID = 519271;
      $imageSizeName = "thumbnail";
      $img = wp_get_attachment_image_src($attachmentID, $imageSizeName);
?>

<img src="<?php echo $img[0]; ?>" alt="image">

An alternative to try if it isn’t working:

<img src="<?php echo wp_get_attachment_url(519271); ?>" alt="image">

This thread discusses your issue further: wp_get_attachment_image_src always returns false


EDIT:

After reading your edit and seeing the site works elsewhere, if it is indeed a corrupted database, try adding this into your wp-config.php file:

define( 'WP_ALLOW_REPAIR', true );

After you have added the line, visit the database repair page: http://your-site.com/wp-admin/maint/repair.php or if you have an SSL certificate, visit https://your-site.com/wp-admin/maint/repair.php.

More information on things that could help found here: https://wpmudev.com/blog/repairing-corrupted-broken-missing-files-databases-wordpress/