感谢您阅读本文。您是否会就如何理解和解决以下两个问题提供一些指导?我是PHP和PostgreSQL的新手。操作系统:OSX 10.9.5,PHP:5.6.4,PostgreSQL:9.4.0
这是一个片段:
$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
这是一个片段:
$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
==
答案 0 :(得分:2)
据我所知,PostgreSQL不支持参数化COPY
语句。根据准备好的陈述(http://www.postgresql.org/docs/9.4/static/sql-prepare.html)的PG 9.4文档,只有SELECT
,INSERT
,UPDATE
,DELETE
或VALUES
陈述可以是参数化。
您可能需要做的是构建COPY
语句并自行插入参数(通过适当的清理和转义以减轻注入等),然后使用pg_query
提交它。