Trying to find if row exists in database. This code always returns TRUE. I want to add the row if it doesn't exist. See test code below.
// CHECK IF RECORD EXISTS
if (array_key_exists('test', $_GET)) {
if(coupleRowExists($_GET['male'], $_GET['female'])) {
echo 'EXISTS';
} else {
echo 'Does NOT exist';
}
}
// CHECK DB FOR THIS COUPLE
function coupleRowExists($male, $female) {
global $db;
$sp_couple_exists = "SELECT EXISTS(SELECT 1 FROM `couples`
WHERE male = ? AND female = ? )";
return ($db->prepare($sp_couple_exists)->execute([$male, $female]));
}
fetchAlland then finally useif elseto see ifrowCountis>= 1. If yes,return trueand if nowreturn false.rowCountdoesnt work for selects.