count($fields)) { return "Invalid BED file--too many or too few columns. Saved as raw."; } else if(strpos($r[1], "chr") !== 0) { return "Invalid BED file--row doesn't begin with 'chr'. Saved as raw."; } $f = array_slice($fields, 0, count($r)); $myfields = join(',', $f); $qmarks = join(',', array_fill(0, count($f), '?')); // insert each row into db $db = getDB(); $sth = $db->prepare("insert into summarybed ($myfields) values ($qmarks)"); $stat = $db->execute($sth, $r); if(PEAR::isError($stat)) { file_put_contents("/tmp/dasrload.log", "Date ".date('YmdHis')." ".print_r($stat, true)); //return $stat->getUserInfo(); return $stat->getMessage(); } $i = 1; while($r = fgetcsv($fp, 0, "\t")) { // trim the row: for($j = count($r) - 1; $r[$j] === ''; $j--) { array_pop($r); } $i++; array_unshift($r, $bedfile_id); $stat = $db->execute($sth, $r); if(PEAR::isError($stat)) { file_put_contents("/tmp/dasrload.log", "Date ".date('YmdHis')."file line $i...\n".print_r($r, true) . print_r($stat, true)); //return $stat->getUserInfo(); return $stat->getMessage(); } } $db->commit(); } ?>