row(s) affected in mysql update with PHP

前端 未结 10 1878
臣服心动
臣服心动 2020-12-10 14:08

How do i find if my update is successful or not? i update using a where uniqueName=name so i should always only update 0 rows or 1. What is a good way to check if i updated

10条回答
  •  执念已碎
    2020-12-10 14:33

    if your update query is in a variable named $query, you can do;

    $result = mysql_query($query);
    if($result){
        //succes!
    } else {
        //fail!
    }
    

    Hope this helps. If you just want to know if your query was executed succesfully, this will do. If you really want to know how many rows are affected, use the other suggestions.

提交回复
热议问题