postgresql - 我的 postgresql 查询有问题

标签 postgresql

我在 mysql 中有一个查询运行良好,但是当我转到 postgresql 时没有更新我,我想知道我的错误在哪里。

我离开了我的 php 文件,查询更新不起作用

<?php
 require_once "Controllers/conexion.php";
 session_start();

    $resultado=pg_query("SELECT nextval('user_id_seq') as key");
    $row=pg_fetch_array($resultado, 0);
    $key=$row['key'];
  try {
$resultado = pg_query($conexion,"select * from encuesta_respuesta where id_user = '".$_SESSION['user']."' and id_encuesta = '".$_POST['id_encuesta']."'");


while( $row = pg_fetch_assoc($resultado)){
    $data = $row;
} 


if ($data['estado']=='F') {
    header("Location: Inicio.php");
}



foreach($_POST['pregunta'] as $id_pregunta=>$valor){
    $query="insert into encuesta_respuesta_opcion values (".$key.",".$_POST['id_encuesta'].",".$id_pregunta.",".$valor.")";
    $resultado = pg_query($conexion,$query);
}


$query="update encuesta_respuesta set estado='F' where id_user=".$_SESSION['user']." and id_encuesta = ".$_POST['id_encuesta']; 
$resultado = pg_query($conexion,$query);    

$resp['error']=false;
 } catch (Exception $e) {
$resp['error']=true;
 }

 header("Location: Inicio.php");
 ?>

最佳答案

直接尝试更新 数据库中的数据,检查此查询是否有效。如果有效,那么您必须更改应用程序中的查询构建过程。例如:

 postgres=# create table test (id_user VARCHAR (50) PRIMARY KEY, id_encuesta VARCHAR (50), estado VARCHAR (10));
 postgres=# insert into test values ('anower','engg.','A');
 postgres=# update test set estado='F' where id_user='anower' and id_encuesta='engg.';

关于postgresql - 我的 postgresql 查询有问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/53614406/

相关文章:

sql - 具有不同条件的多个 AVG 列

sql - 通过查看所有列删除重复的 SQL 行

SQLGrammer异常 : could not execute statement

sql - 返回对应值变化的账户的所有历史账户记录

postgresql - 计算几个卖家之间的最佳销售

regex - PostgreSQL,用于将文本字段与数值匹配的正则表达式

performance - 如何处理卡住的 PostgreSQL 9.3 VACUUM ANALYZE?

postgresql - 容器的镜像更新到最新后,Postgres 容器崩溃并显示 `database files are incompatible with server`

python - Django 无法在 Docker 设置中连接到 Postgres

mysql - PostgreSQL:SET 相当于 MySQL