使用PDO插入postgres数据库

时间:2019-07-20 19:33:06

标签: php postgresql php-pgsql

我正在尝试使用php中的pdo连接将一些数据插入到postgres数据库中。连接成功,但是插入查询给出了语法错误,我无法弄清楚我的语法出了什么问题。

$dbcon->setAttribute(PDO::ATTR_ERRMODE, PDO::ERRMODE_EXCEPTION);
$id = "12345";
$name = "Sueaj Roy";
$fname = "Biplab Roy";
$aadhaar = "5678973";
$dob = "22/12/90";
$statement = $dbcon->prepare("INSERT INTO user (full_name, father_name, dob, aadhaar_no, id) VALUES (:A,:B,:C,:D,:E)");
$statement->bindValue(':A', $name);
$statement->bindParam(':B', $fname);
$statement->bindParam(':C', $dob);
$statement->bindParam(':D', $aadhaar);
$statement->bindParam(':E', $id);
$statement->execute();

enter image description here

我的桌子

enter image description here

1 个答案:

答案 0 :(得分:1)

user是Postgres中的保留字。如果您命名任何对象user,则必须用双引号将该名称引起来。

INSERT INTO "user"
            ...
相关问题