I am not sure how you use your metabox (and why??) , nor why would you do a direct SQL query in the code , but normally, this is how you would pull image (attachment) data :
$alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
$image_title = $attachment->post_title;
$caption = $attachment->post_excerpt;
$description = $image->post_content;
Since atatchments in wp are actually a built in CPT ( actually a post) :
The attachment caption is actually the post excerpt The attachment title is the post title The attachment description is the post content .
so a full code woule be more along the lines of :
$args = array( 'post_type' => 'attachment',
'orderby' => 'menu_order',
'order' => 'ASC',
'post_mime_type' => 'image' ,
'post_status' => null,
'numberposts' => null,
'post_parent' => $post->ID );
$attachments = get_posts($args);
if ($attachments) {
foreach ( $attachments as $attachment ) {
$alt = get_post_meta($attachment->ID, '_wp_attachment_image_alt', true);
$image_title = $attachment->post_title;
$caption = $attachment->post_excerpt;
$description = $attachment->post_content;
}
}