Re: PHP and COPY

From: Adam Witney <awitney(at)sghms(dot)ac(dot)uk>
To: DeJuan Jackson <djackson(at)speedfc(dot)com>, pgsql-php <pgsql-php(at)postgresql(dot)org>
Subject: Re: PHP and COPY
Date: 2003-08-16 12:21:53
Message-ID: BB63E071.226B6%awitney@sghms.ac.uk
Views: Raw Message | Whole Thread | Download mbox | Resend email
Thread:
Lists: pgsql-php


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)."<br>\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

In response to

Browse pgsql-php by date

  From Date Subject
Next Message dash 2003-08-18 17:30:31 Authentication Failure with pg_pconnect
Previous Message DeJuan Jackson 2003-08-15 22:18:57 Re: PHP and COPY