亚洲在线久爱草,狠狠天天香蕉网,天天搞日日干久草,伊人亚洲日本欧美

為了賬號安全,請及時綁定郵箱和手機立即綁定
已解決430363個問題,去搜搜看,總會有你想問的

致命錯誤:未捕獲的 PDOException:SQLSTATE[HY093]:

致命錯誤:未捕獲的 PDOException:SQLSTATE[HY093]:

C#
慕田峪9158850 2021-11-05 16:07:56
我正在嘗試通過 php 對 postgresql 數據庫運行更新查詢。當我嘗試這樣做時,出現錯誤。我嘗試將其更改id = ?為id = :id但沒有用我的update功能://update a student    public function updateStudent(){      $query = 'UPDATE ' . $this->table . ' ( name, course) VALUES ( :name, :course) WHERE id = ? ;';      $stmt = $this->conn->prepare($query);      $this->id = htmlspecialchars(strip_tags($this->id));      $this->name = htmlspecialchars(strip_tags($this->name));      $this->course = htmlspecialchars(strip_tags($this->course));      $stmt->bindParam(':id', $this->id);      $stmt->bindParam(':name', $this->name);      $stmt->bindParam(':course', $this->course);      if($stmt->execute()){        return true;      }      //print error      printf("Error: %s.\n", $stmt->error);      return false;    }錯誤: Fatal error: Uncaught PDOException: SQLSTATE[HY093]: Invalid parameter number: mixed named and positional parameters in...它說錯誤在第 58 行,這行內容是: $stmt = $this->conn->prepare($query); 我的錯誤在 58 行之上。更新:如果我使用id = :id而不是id = ?,我會收到以下錯誤:Fatal error: Uncaught PDOException: SQLSTATE[42601]: Syntax error: 7 ERROR: syntax error at or near "(" LINE 1: UPDATE students ( name, course) VALUES ( $1, $2) WHERE id = ... ^ in
查看完整描述

1 回答

?
慕村225694

TA貢獻1880條經驗 獲得超4個贊

你不能使用 :param 和 ? 使用 :id 而不是 ?


但是對于更新,您可以使用


    'UPDATE ' . $this->table . ' 

        set  name = :name, 

         course = :course 

      WHERE id = :id ;';





   public function updateStudent(){

      $query = 'UPDATE ' . $this->table . ' 

                  set  name = :name, 

                       course = :course 

                WHERE id = :id ;';

      $stmt = $this->conn->prepare($query);


      $this->id = htmlspecialchars(strip_tags($this->id));

      $this->name = htmlspecialchars(strip_tags($this->name));

      $this->course = htmlspecialchars(strip_tags($this->course));

      $stmt->bindParam(':id', $this->id);

      $stmt->bindParam(':name', $this->name);

      $stmt->bindParam(':course', $this->course);


      if($stmt->execute()){

        return true;

      }

      //print error

      printf("Error: %s.\n", $stmt->error);

      return false;

    }


查看完整回答
反對 回復 2021-11-05
  • 1 回答
  • 0 關注
  • 531 瀏覽

添加回答

舉報

0/150
提交
取消
微信客服

購課補貼
聯系客服咨詢優惠詳情

幫助反饋 APP下載

慕課網APP
您的移動學習伙伴

公眾號

掃描二維碼
關注慕課網微信公眾號