0

Is it possible to use the postgresql COPY command in a php file?

I need to download table content from a database table to a file using a php script

    $sql = " COPY tablename TO STDOUT WITH DELIMITER ',' ";

    $db->query( $sql );

This code does not work for me, what is the right way?

1
  • 2
    "not works" is not a valid Postgres error message (and I doubt it's a valid PHP error message either). Commented Apr 22, 2013 at 14:20

1 Answer 1

2

php provides pg_copy_to that implements COPY to a php array, one element per row.

$rows = pg_copy_to($connection, "tablename", ",");
Sign up to request clarification or add additional context in comments.

1 Comment

But what if I don’t want to export a table but a query? And don’t want to get a rows array but stream to stdout?

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.