Forgot about COPY command in my previous reply:
$conn = pg_pconnect("dbname=foo"); $fd = fopen('file.dat', 'r'); pg_query($conn, "copy bar from stdin"); while (!feof($fd)) { pg_put_line($conn, fgets($fd)); } fclose($fd); pg_put_line($conn, "\\.\n"); pg_end_copy($conn);