X-Original-To: pgsql-php-postgresql.org@localhost.postgresql.org Received: from localhost (unknown [64.117.224.130]) by svr1.postgresql.org (Postfix) with ESMTP id C34F8D1B8BB for ; Sat, 16 Aug 2003 12:23:30 +0000 (GMT) Received: from svr1.postgresql.org ([64.117.224.193]) by localhost (neptune.hub.org [64.117.224.130]) (amavisd-new, port 10024) with ESMTP id 75847-03 for ; Sat, 16 Aug 2003 09:23:23 -0300 (ADT) Received: from mk-smarthost-3.mail.uk.tiscali.com (mk-smarthost-3.mail.uk.tiscali.com [212.74.114.39]) by svr1.postgresql.org (Postfix) with ESMTP id 8ED5BD1B8B7 for ; Sat, 16 Aug 2003 09:23:19 -0300 (ADT) Received: from [80.47.210.146] (helo=[80.47.210.146]) by mk-smarthost-3.mail.uk.tiscali.com with esmtp (Exim 4.20) id 19o05Y-000Py4-LT; Sat, 16 Aug 2003 13:23:21 +0100 User-Agent: Microsoft-Entourage/10.1.1.2418 Date: Sat, 16 Aug 2003 13:21:53 +0100 Subject: Re: PHP and COPY From: Adam Witney To: DeJuan Jackson , pgsql-php Message-ID: In-Reply-To: <3F3D235D.6090005@speedfc.com> Mime-version: 1.0 Content-type: text/plain; charset="US-ASCII" Content-transfer-encoding: 7bit X-Virus-Scanned: by amavisd-new at postgresql.org X-Archive-Number: 200308/66 X-Sequence-Number: 2243 Try something along these lines..... (this snippet is untested but should get you started) $dbh = pg_connect($connstr); $sql = "COPY table (field1, field2, field3) from stdin;"; $result = pg_query($dbh, $sql); $data = "blah\tblah\tblah\n"; $stat = pg_put_line($dbh, $data); if(!$stat) { echo "copy failed: ".pg_errormessage($dbh)."
\n"; } pg_put_line($dbh, "\\.\n"); pg_end_copy($dbh); > Does anyone know how to execute a COPY from PHP? > I keep getting parse errors on all the data. > > PHP 4.3.2 > PostgreSQL 7.3.4 > > example: > > CREATE table tmp(data text); > > COPY tmp FROM STDIN; > test1 > test2 > test3 > \. > > > > ---------------------------(end of broadcast)--------------------------- > TIP 7: don't forget to increase your free space map settings