. */ $sql = ''; $fd = fopen('../docs/developer/pulses.dummy.copy', 'r'); if ($fd) { while (!feof($fd)) { $buffer = explode("\t", fgets($fd)); $ts = parsePgSqlTimestamp($buffer[0]); if ($ts > 0) $pulses[] = '(' . (int) ($buffer[2] + 1) . ', ' . $ts . ', 1)'; }; fclose($fd); $sql = 'INSERT INTO data (channel_id, timestamp, value) VALUES ' . implode(', ', $pulses); $dbh->execute($sql); echo 'Imported rows: ' . $dbh->affectedRows(); } else { throw new Exception('cant open dump'); } function parsePgSqlTimestamp($timestamp) { $unix = strtotime($timestamp); $ms = substr($timestamp, strrpos($timestamp, '.') + 1); return $unix + $ms/pow(10, strlen($ms)); } ?>