How to get the parent comments (in a custom module)?
This code does the trick:

  $threads = explode('.', $comment-&gt;thread);
  $thread = "";
  $pnids = array();
  for($i=0;$i&lt;(count($threads)-1);$i++){
        $thread .= $threads[$i];
        $local_thread = $thread."/";
        $result = db_query('SELECT c.cid FROM {comment} c WHERE c.nid = :nid AND c.thread = :thread AND c.status = :status',
        array(':nid' =&gt; $comment-&gt;nid, ':thread' =&gt; $local_thread, ':status'=&gt;'1'));
        foreach ($result as $record) {
            $pnids[] = $record-&gt;cid;
        }
        $thread .= ".";
  }


However this code produces 1 DB query for each parent. I don't know if it is feasible/better to include all the :thread in a single query with OR.