In PHP PDO trying to use SELECT COUNT(*) SQL
to see if primary key exists (so then can update rather than insert),
When I call the function sqlCall; fetchColumn()
returns 0 or 1 depending on if it exists or not, however when it is returned it always returns false?
How do I get it to return if row exists or not?
Thanks for help!!
function sqlCall($primary) {
$sql = $handler->prepare("SELECT COUNT(*) FROM WHERE ". strtolower($primary)."=:".$primary);
$sSqlParams = array(':'.$primary => $primary);
$sql->execute($sSqlParams);
if($sql->fetchColumn()==1){
return 1;
} else {
return 0;
}
break;
}
try {
$rows = sqlCall($primary);
if($rows=True){
//UPDATE SQL
} else {
//INSERT SQL
}
}
catch(PDOException $er) {
die();
}