【问题标题】:how to insert null in postgres with php如何使用 php 在 postgres 中插入 null
【发布时间】:2021-08-11 03:36:15
【问题描述】:

我正在尝试使用 php 将 null 插入到 postgres 数据库中。说我有这个:

<?php
$sql = <<<EOT
insert into
    t1
(c1, c2)
values
($param, 'test')
EOT;
?>

我尝试将 $param 设置为:

$param = null;
$param = '\N';

在每种情况下我都收到此错误:

Native message: ERROR:  syntax error at or near ","

我需要把它设置成什么?

【问题讨论】:

  • 1.准备好的陈述。 2.NULL.

标签: php postgresql null


【解决方案1】:

您可以使用 PDO:

$query = "INSERT INTO t1 VALUES(?,?)";
$insertStatement = $pdo->prepare($query);
$insertStatement->execute([null, 'test']);

Execute PHP online

【讨论】:

    【解决方案2】:
    $param = 'null';
    

    它应该可以工作。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 2014-05-19
      • 2012-12-29
      • 1970-01-01
      • 1970-01-01
      • 2021-03-07
      • 2017-04-26
      • 2016-03-11
      • 2021-09-18
      相关资源
      最近更新 更多