Determine if only one image attached to a post/page

That code should get the attachments as array which you should be able to use count() on to determine the total number of images. Example:

if ( $attachments ) {
    if ( 1 == count( $attachments ) ) {
      // handle single image
    } else {
      // handle multiple images
    }
}

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