如何使用php在postgres中插入null

如何使用php在postgres中插入null,php,postgresql,null,Php,Postgresql,Null,我试图用php将null插入postgres数据库。假设我有这个: <?php $sql = <<<EOT insert into t1 (c1, c2) values ($param, 'test') EOT; ?> 在每种情况下,我都会犯下这样的错误: Native message: ERROR: syntax error at or near "," 我需要将其设置为什么 $param = 'null'; 它应该会起作用 它

我试图用php将null插入postgres数据库。假设我有这个:

<?php
$sql = <<<EOT
insert into
    t1
(c1, c2)
values
($param, 'test')
EOT;
?>
在每种情况下,我都会犯下这样的错误:

Native message: ERROR:  syntax error at or near ","
我需要将其设置为什么

$param = 'null';
它应该会起作用


它应该可以工作。

您可以使用PDO进行操作:

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

您可以使用PDO执行此操作:

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

1。准备好的发言。2. <代码>空值.1。准备好的发言。2. <代码>空值。