PHP: Update multiple MySQL fields in single query

后端 未结 4 1575
清歌不尽
清歌不尽 2020-12-05 08:09

I am basically just trying to update multiple values in my table. What would be the best way to go about this? Here is the current code:

$postsPerPage = $_PO         


        
4条回答
  •  一生所求
    2020-12-05 09:00

    If you are using pdo, it will look like

    $sql = "UPDATE users SET firstname = :firstname, lastname = :lastname WHERE id= :id";
    $query = $this->pdo->prepare($sql);
    $result = $query->execute(array(':firstname' => $firstname, ':lastname' => $lastname, ':id' => $id));
    

提交回复
热议问题