Re: PHP and COPY

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]



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



[Index of Archives]     [Postgresql General]     [Postgresql Admin]     [PHP Users]     [PHP Home]     [PHP on Windows]     [Kernel Newbies]     [PHP Classes]     [PHP Databases]     [Yosemite Backpacking]     [Postgresql Jobs]

  Powered by Linux