Use get_comments( $args )
to get all the comments for a post.
$args= array(
'author_email' => '',
'ID' => '',
'karma' => '',
'number' => '',
'offset' => '',
'orderby' => '',
'order' => 'DESC',
'parent' => '',
'post_id' => 0,
'post_author' => '',
'post_name' => '',
'post_parent' => '',
'post_status' => '',
'post_type' => '',
'status' => '',
'type' => '',
'user_id' => '',
'search' => '',
'count' => false,
'meta_key' => '',
'meta_value' => '',
'meta_query' => '');
You can set post_id
here and get all comments related to that post. It is same as your query.
$comments = get_comments(array('post_id'=> 'your post id'));
$comment_ids = array();
foreach($comments as $comment):
$comment_ids[] = $comment->comment_ID;
endforeach;
print_r(comment_ids);
For reference http://codex.wordpress.org/Function_Reference/get_comments