我无法找到为什么此查询不起作用的答案:
$query = pg_query($connect, sprintf("INSERT INTO table (uid, urzid, time_start, time_stop2, date_start, date_stop, cycle) VALUES ($uid, $pom, '$time1', '$time2', '$data1', '$data2', $cykl)"));
我收到一条警告:PG_QUERY()[FUNCTION.PG-QUERY]:QUERY FAILED:ERROR:语法错误在“或”附近“,”字符96
在我看来,错误与。''$ time1,$ Time2和$ date1,$ date2符合日期和时间的格式。
答案 0 :(得分:5)
答案 1 :(得分:2)
我们无法猜测变量中的内容。 请运行此代码并粘贴结果:
echo "INSERT INTO table (uid, urzid, time_start, time_stop2, date_start, date_stop, cycle) VALUES ($uid, $pom, '$time1', '$time2', '$data1', '$data2', $cykl)";
您会发现语法错误。
避免此类错误(更重要的是,阻止SQL injection)的最佳方法是使用PDO等库并对变量使用placeholders
更新:现在我们可以看到你的变量是什么样的,试试这个:
$query = pg_query($connect, "INSERT INTO table (uid, urzid, time_start, time_stop2, date_start, date_stop, cycle) VALUES ('$uid', '$pom', '$time1', '$time2', '$data1', '$data2', '$cykl')");
不要忘记查看以上评论中的最佳做法。
答案 2 :(得分:0)
尝试撤消引用,“=>',”=> '...总是给我带来很多痛苦。
答案 3 :(得分:0)
您必须添加额外的参数:
$world = "World";
$foo = sprintf("Hello %s", $world);
但是,由于您使用双引号字符串,因此不需要sprintf:
$foo = "Hello $world";