php - No mySQL error thrown while trying to UPDATE an empty row
Building a small project and trying to learn as I go along.
I get error codes fine if tables are misnamed etc but if I try to UPDATE an empty row I do not get an error. I want to but it isn't telling me I have screwed up. Is this normal?
public function updateMessage($id){ //done
try{
global $pdo;
$temp=$this->_message;
$sql = "UPDATE message SET content=:val WHERE id=$id";
$s = $pdo->prepare($sql);
$s->bindValue(':val',$temp);
$s->execute();
}
catch (PDOException $e)
{ $loc = $_SERVER['PHP_SELF'];
$output = "Unable to connect to the database server: $loc <br><h3>Please contact
Steve via text on ###### quoting:</h3><h5>" . $e->getMessage() . "<br>
Found at $loc.</h5>
<h3>Thanks. </h3>". "<br>"."<br>" ;
include $_SERVER['DOCUMENT_ROOT'] ."/beta01/includes/output.html.php";
exit();
}
}
As I said it works as expected with most errors just not on the empty update problem.
Answer
Solution:
If it's an "empty row" (assuming I understand you right), then it doesn't meet the condition
WHERE id=$id
, so it worked - it updated the contents of message for every row with that id (there were none).It sounds like you want to know if no rows were affected by the query, in which case you could do: