pg_put_line and file()

From: Date: Sat, 27 Jan 2001 15:28:02 +0000
Subject: pg_put_line and file()
Groups: php.db 
Request: Send a blank email to php-db+get-6221@lists.php.net to get a copy of this message
Hi. I was tinkering around with pg_put_line and pg_end_copy and rather than inserting data from a variable as per the example, I was wondering if it was posible to insert the data from a delimited file via these two functions. I produced a dump from postgres and tried inserting the data raw $text = file("test.sql"); $db = pg_connect("host=localhost dbname=testing user=testing"); pg_exec($db, "COPY test FROM stdin"); foreach($text as $line) { echo $line, "<BR>"; pg_put_line($db,$line); flush(); } pg_end_copy($db); but this caused an error to occur. The example in the docs had the new lines and tabs escaped so I tried that as well with addslashes() $text = file("test.sql"); $db = pg_connect("host=localhost dbname=graeme user=graeme"); pg_exec($db, "COPY test FROM stdin"); foreach($text as $line) { $line = addslashes($line); $line = ereg_replace(9,"\\t",$line); $line = ereg_replace(10,"\\n",$line); echo $line, "<BR>"; pg_put_line($db,$line); flush(); } pg_end_copy($db); and while the data was exactly the same format as the example, I managed to get postgres stuck in COPY and had to manually kill the postgres COPY process to recover. Any one have any ideas? Cheers, Graeme

« previous php.db (#6221) next »