php - 查询未执行

标签 php postgresql

我是 postgresql 的新手,我不知道查询中的语法错误是什么。当我执行以下查询时会发生什么......它在 pgadmin 中显示语法错误......

$sql1 = "INSERT INTO cpmu_phy_achivement(implementor, scheme_code, phycomp_code, month_code, finmonthcode, year_code, target_ach, updated_by, remarks, ason, reason_code)
VALUES (0,'$schemecode', $phycompcode, $entrymonth, $finmonthcode, $finyearcode, $targetach, '$empcode', '$remarksave', '$as_onsave', $reason_codesave)";

当我回应查询时..它显示为..

INSERT INTO cpmu_phy_achivement( implementor, scheme_code, phycomp_code, month_code, finmonthcode, year_code, target_ach, updated_by, remarks, ason, reason_code) 
VALUES (0, 'AGR3-17', 3, 6, 6, 2017, 0, '13', '', '2017-07-12', )

如果我插入原因代码,它会成功执行..但是当原因代码为空时..发生错误..帮助我解决这个问题..请..

最佳答案

我强烈建议您使用准备好的语句。他们会处理这种边缘情况。

首先,阅读pg_prepare的手册.

您的代码将如下所示:

$sql1 = "INSERT INTO cpmu_phy_achivement(implementor, scheme_code, phycomp_code, month_code, finmonthcode, year_code, target_ach, updated_by, remarks, ason, reason_code)
VALUES (?,?,?,?,?,?,?,?,?,?,?)";

$stmt = pg_prepare($connection, $sql1);
$values = array(0,$schemecode, $phycompcode, $entrymonth, $finmonthcode, $finyearcode, $targetach, $empcode, $remarksave, $as_onsave, $reason_codesave);
$result = pg_execute($connection, $stmt, $values);

请注意,您不必处理值的字符串或数字表示。

进一步阅读:

您可以使用 pg_query_params如果您不想像 Craig Ringer 建议的那样重用 sql 语句。

关于php - 查询未执行,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/45052136/

相关文章:

php - 在 foreach 中获取更多数据

php - 我想在 MySQL 数据库中有一列自动计算 DATETIME 差异

php - 使用 PHP 将 JavaScript 数组保存到服务器

Postgresql psql命令转储错误

postgresql - 生成 Postgres 转储并保存到另一台服务器

python - psycopg2.InterfaceError : connection already closed/pgr_astar

php - 如何创建平均分布的三人小组?

php - 无法使用 laravel 和 vue js 运行 watch

java - 按代码排序

postgresql - 由于子查询,查询速度极慢