gpt4 book ai didi

php - 警告 : pg_query() [function. pg-query]:查询失败:错误:未终止的引号字符串位于或附近

转载 作者:行者123 更新时间:2023-11-29 13:06:11 25 4
gpt4 key购买 nike

我有一个查询出现错误:

代码是:

$prefix = $data->sheets[0]['cells'][$row][2];
$fiyat = $data->sheets[0]['cells'][$row][3];
$increment = $data->sheets[0]['cells'][$row][4];
$tarih = $data->sheets[0]['cells'][$row][5];
$tarih = explode('.',$tarih);
$effective_date = $tarih[2] . "-" . $tarih[1] . "-" . $tarih[0];

所有变量都返回正确的值(和变量类型)。

$query_insert_to_rates = "INSERT INTO rates VALUES (nextval('routes_seq'), '$prefix', '$i_tariff', '$fiyat_orj', '$fiyat_orj', '$increment', '$increment', '$forbidden', 't', '0', '0', '$increment', '$increment', NULL, '$eff_date_ins', NULL);";

$result_insert_to_rates = pg_query($query_insert_to_rates);

INSERT INTO rates VALUES (nextval('routes_seq'), '21321', '8', '0.0470', '0.0470', '1', '1', 't', 't', '0', '0', '1', '1', NULL, '2012-06-01 00:00:00.000001+02', NULL);

Warning: pg_query() [function.pg-query]: Query failed: ERROR: unterminated quoted string at or near "'2" at character 50 in.....

现在,当我在 PHP 中运行查询时,出现上述错误。我的 PHP 版本是 5.3.10。而且机器是Centos 5(VPS)。

但是,如果我通过 Navicat(连接到数据库)运行查询,那么我没有错误,并且查询执行得很完美。

如有任何帮助,我们将不胜感激。

最佳答案

这是糟糕的代码:不安全且不安全。永远不要使用这种模式

$SQL = "INSERT ... ('$var1', '$var2')

改用 PDO 参数化查询或 pg_escape_string 函数

pg_escape_string

关于php - 警告 : pg_query() [function. pg-query]:查询失败:错误:未终止的引号字符串位于或附近,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/10964678/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com