Add link to attachment for old posts

You can use the the_content filter to access the contents of the post before it is printed to the screen. The function that you use to filter it can either go two routes – using regex to parse the contents (not the “right” way but faster/dirtier) or an HTML parser. You should then be able to get to the src attribute and replace the <img/>.

function my_content_filter( $post_content ){
    // parse and modify the <imgs> in $post_content here
    return $post_content;
}
add_filter( 'the_content', 'my_content_filter' );

Keep in mind that if you go this route, the modified content’s won’t actually be stored in the database, so if something accesses $post->post_content without calling apply_filters( 'the_content', $post->post_content ) then your links won’t be included. This will also put a relatively high load on your server to parse/modify the contents on every request, especially without a caching plugin in place. Programmatically accessing and updating the saved values might be a better choice if you want the updates to be ubiquitous.

Hata!: SQLSTATE[HY000] [1045] Access denied for user 'divattrend_liink'@'localhost' (using password: YES)