Reputation: 54
I have a query like this:
$query="INSERT IGNORE INTO mytable (key, word1, word2) VALUES (1, 'abc', 'def')";
And I'd like to somehow "catch" if the query was ignored because the primary key already exists.
Is there any was to make an "if" statement so my program could notify the user that the query was ignored?
Upvotes: 0
Views: 276
Reputation: 54
I solved it by using mysql_affected_rows
to check if no rows were affected by the query.
if($productquery&&mysql_affected_rows($conn)>0){
echo "Success.";
echo mysql_affected_rows($conn); //returns 1
}else{
echo "Some error." . mysql_error(). " ".mysql_affected_rows($conn); //returns 0 affected rows since it was ignored
}
Upvotes: 2
Reputation: 27325
The problem is when you especially ignore the errors then you don't get them. So you have to remove the IGNORE and catch the error instead.
You don't get any errors in your case.
Upvotes: 1