【问题标题】:I cannot insert a data with Postgre and PHP我无法使用 Postgres 和 PHP 插入数据
【发布时间】:2017-03-22 11:02:39
【问题描述】:

我正在使用 PHP 和 Postgre 开发软件。所以,我有插入代码的问题:

function create(){
    $query = "INSERT INTO " . $this->table_name . " VALUES (" . $this->pess_nome . ")";

    $result = pg_query($this->conn, $query);

    if($result){
        return true;
    }else{
        return false;
    }
}

错误信息:

警告:pg_query(): Query failed: ERROR: column "test" does not exist LINE 1: INSERT INTO pessoa VALUES (test) ^ in C:\xampp\htdocs\Projeto_GPass\objects\pessoa.php 第 26 行

【问题讨论】:

    标签: php postgresql crud


    【解决方案1】:

    SQL 查询中的字符串值需要用撇号或引号括起来。将代码的第二行修改为:

    $query = "INSERT INTO " . $this->table_name . " VALUES ('" . $this->pess_nome . "')";
    

    编辑:当您在查询中使用字符串值并且不将其括在引号 ("test") 或撇号 ('test') 中时,PostgreSQL 会将其作为列的名称,因此会出现错误消息。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 2012-10-03
      • 1970-01-01
      • 1970-01-01
      • 2018-01-16
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多