[英]how to insert null in postgres with php
我正在尝试使用 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 ","
我需要将其设置为什么?
$param = 'null';
它应该工作。
您可以使用 PDO 来做到这一点:
$query = "INSERT INTO t1 VALUES(?,?)";
$insertStatement = $pdo->prepare($query);
$insertStatement->execute([null, 'test']);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.