How to Verify the Success of a MySQL Query in Modifying Database Data
In PHP, you can utilize the affected_rows property of the statement object to determine whether a query successfully modified the database table data. Consider the following code snippet:
<code class="php">if($cmd=="deleterec"){ $deleteQuery = "DELETE FROM AUCTIONS1 WHERE ARTICLE_NO = ?"; if ($delRecord = $con->prepare($deleteQuery)) { $delRecord->bind_param("s", $pk); $delRecord->execute(); $rowCount = $delRecord->affected_rows; $delRecord->close(); echo ($rowCount > 0) ? "true" : "false"; } else { echo "false"; } }</code>
In this code:
By using affected_rows, you can accurately determine the success or failure of the query in modifying the database table data.
The above is the detailed content of How to Check if a MySQL Query Successfully Modified Database Data in PHP?. For more information, please follow other related articles on the PHP Chinese website!