PHP, MySQL, PDO - Get result from UPDATE query?

后端 未结 3 1444
说谎
说谎 2020-12-20 11:29

I am updating a row in a table, and trying to return the updated row, as per this SO answer.

My code is the following:

$sql = \"SET @update_id := \'\         


        
3条回答
  •  太阳男子
    2020-12-20 12:22

    It's failing on ->fetchAll() because an UPDATE query does not return any rows/data.

    What you want to do, is check out PDO::rowCount(). This returns the count of how many rows have been affected by your query.

    echo $stmt->rowCount();
    

    This was posted assuming you're trying to check if your query was successful.

提交回复
热议问题