get second ID from array

Your function is called “replace_thumbnail” so I am assuming you are trying to set/replace the post thumbnail (featured image):

function replace_thumbnail($id) {
  $image_ids = array();
  $media = get_attached_media( 'image', $id );;
  foreach($media as $item) {
    $image_ids[] = $item->ID;
  }
  // insert your featured image
  if (!empty($image_ids[1])) {
    update_post_meta( $id, '_thumbnail_id', $image_ids[1] );
  }
  // 
  $image_ids_str = implode(',',$image_ids);
  update_post_meta( $id, '_easy_image_gallery', $image_ids_str );
}

You can use any other key besides _thumbnail_id if my assumption is wrong.

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