使用Postgres

时间:2018-10-04 10:58:16

标签: php postgresql

我正在尝试创建3个相互连接的页面。

请求页面 页面已删除 页面已接受

数据库中的哪个对应于:

prenotaziones Prenotazione认证 prenotazioneCancellate

当用户填写表单字段时,将在“请求页面”中进行输入。从这里开始,请求可以被接受或拒绝。并且每次接受或拒绝请求时,都会将其从“请求页面”中删除。

现在的问题是,虽然在mysql中所有这些过程都对我来说是完美的,但在postgres上,我的代码唯一要做的就是从“请求”中删除,而在其他页面上不插入任何内容。

这是代码:

 <td>
        <a href="prenotazioniRichieste.php?delete=<?php echo $id; ?>"onclick="return confirm ('Are you sure?');"><img src="image/cross.png"></a>
    </td>
    <td>
        <a href="prenotazioniRichieste.php?accept=<?php echo $id; ?>"onclick="return confirm ('Are you sure?');"><img src="image/check.png"></a>
    </td>

    </tr>

    <?php
     $i++;
    }
    if(isset($_GET['delete'])){
           $delete_id = $_GET['delete'];
        //   mysqli_query($dbh,"INSERT INTO PrenotazioneCancellate SELECT * FROM Prenotazione WHERE id='$delete_id'");
        //   mysqli__query($dbh,"DELETE FROM prenotaziones WHERE id='$delete_id'");
        // header("location: prenotazioniRichieste.php");


        $sqld1 = "INSERT INTO prenotazioneCancellate SELECT * FROM prenotaziones WHERE id='$delete_id'";
            $resultd1 = $dbh->prepare($sqld1);
            $resultd1->execute();
        $sqld2 = "DELETE FROM prenotaziones WHERE id='$delete_id'";
            $resultd2 = $dbh->prepare($sqld2);
            $resultd2->execute();

    }

    if(isset($_GET['accept'])){
           $accept_id = $_GET['accept'];
       //    mysqli_query($dbh,"INSERT INTO PrenotazioneAccettate SELECT * FROM Prenotazione WHERE id='$accept_id'");
       //    mysqli_query($dbh,"DELETE FROM Prenotazione WHERE id='$accept_id'");
       //    header("location: prenotazioniRichieste.php");
        $sqla1 = "INSERT INTO PrenotazioneAccettate SELECT * FROM prenotaziones WHERE id='$accept_id'";
            $resulta1 = $dbh->prepare($sqla1);
            $resulta1->execute();
        $sqla2 = "DELETE FROM prenotaziones WHERE id='$accept_id'";
            $resulta2 = $dbh->prepare($sqla2);
            $resulta2->execute();
    }
    echo "</table>";
?> 

1 个答案:

答案 0 :(得分:1)

第一个更改是:

$sqld1 = "INSERT INTO \"prenotazioneCancellate\" SELECT * FROM prenotaziones WHERE id='$delete_id'";

第二个时间是(如果您使用PDO和预准备的语句,并且不想担心变量和sql-injections):

 $sqlQuery = "INSERT INTO public.\"prenotazioneCancellate\" 
                  SELECT * FROM public.prenotaziones 
              WHERE public.prenotaziones.id=:id_to_delete";
 $loStatement = $dbh->prepare($sqlQuery);
 $loStatement->bindValue(':id_to_delete', $delete_id, PDO::PARAM_INT);
 $loStatement->execute();
 $loResult = loStatement->fetchAll();

在postgres中,您的数据库可以分布在模式中。多数民众赞成例如上市。您可以使用带有大写字母的表格,但必须以正确的方式对其进行转义。 您的删除工作会导致表名始终使用小写字母:prenotaziones

和最后一个:

try {
   $sqlQuery = "INSERT INTO public.\"prenotazioneCancellate\" 
                      SELECT * FROM public.prenotaziones 
                  WHERE public.prenotaziones.id=:id_to_delete";
   $loStatement = $dbh->prepare($sqlQuery);
   $loStatement->bindValue(':id_to_delete', $delete_id, PDO::PARAM_INT);
   $loStatement->execute();
   $loResult = loStatement->fetchAll();
}
catch(Exception $e) {
//do something with the error
}