I am using PHP's PDO (with mysql server) to update a table. Something similar to the query:
UPDATE game g
SET g.some_field=1
WHERE g.game_id=:game_id AND g.is_finished=1
AND (g.player1=:player_id OR g.player2=:player_id)
LIMIT 1
executed like this:
$psResult = $ps->execute();
if( !$psResult ){
// database error
} else if( $ps->rowCount() <= 0 ){
// no row was updated.
}
Now the else-if statement that does the rowCount() check can be 0 when:
:game_id
which has is_finished
set to 1 and has :player_id
as either player1
or player2
.some_field
was already set to 1.I need to distinguish these in order to return a correct error/value. For example return true if the field was set to 1 or already had 1 and return false if no record was matched.
How can I do this? Is there another way then doing an extra query?