Reputation: 3
Thank you for reading this. Would you provide some pointers as to how to understand and solve the two questions below? I am new to PHP and PostgreSQL. OS: OSX 10.9.5, PHP: 5.6.4, PostgreSQL: 9.4.0
Here is a snippet:
$params = array(strval($_POST['que_str2']));
$myresult = pg_query_params($connection, 'copy $1 from stdin', $params);
echo "<br />\n$params[0] <br />\n";
Warning: pg_query_params(): Query failed: ERROR: syntax error at or near "$1" LINE 1: copy $1 from stdin ^ in /Library/WebServer/Documents/test.php
my_table
Here is a snippet:
$params = array(strval($_POST['que_str2']), strval($_POST['que_str1']));
$myresult = pg_query_params($connection, 'copy $1 from $2 DELIMITERS \',\' CSV', $params);
echo "<br />\n$params[0] $params[1]<br />\n";
Warning: pg_query_params(): Query failed: ERROR: syntax error at or near "$1" LINE 1: copy $1 from $2 DELIMITERS ',' CSV ^ in /Library/WebServer/Documents/test.php on line 20
my_table /Library/WebServer/Documents/data2.csv
==
Upvotes: 0
Views: 543
Reputation: 5246
As far as I know, PostgreSQL does not support parameterized COPY
statements. Per the PG 9.4 docs on prepared statements (http://www.postgresql.org/docs/9.4/static/sql-prepare.html), only SELECT
, INSERT
, UPDATE
, DELETE
, or VALUES
statements can be parameterized.
What you may have to do is construct the COPY
statement and interpolate the parameters yourself (with appropriate scrubbing and escaping to mitigate injection, etc.) and then submit it with pg_query
instead.
Upvotes: 2