I have the following functions:
function getExample($id, $otherid) {
global $db;
$query = 'SELECT * FROM examples WHERE id = :id AND otherid= :otherid';
try {
$statement = $db->prepare($query);
$statement->bindValue(':id', $id);
$statement->bindValue(':otherid', $otherid);
$statement->execute();
$result = $statement->fetchAll();
$statement->closeCursor();
return $result;
} catch (PDOException $e) {
$error_message = $e->getMessage();
display_db_error($error_message);
}
}
function getSecExample($id) {
global $db;
$query = 'SELECT * FROM examples WHERE id= :id';
try {
$statement = $db->prepare($query);
$statement->bindValue(':id', $id);
$statement->execute();
$result = $statement->fetchAll();
$statement->closeCursor();
return $result;
} catch (PDOException $e) {
$error_message = $e->getMessage();
display_db_error($error_message);
}
}
Is there a way to make this one function instead of two? I want it to be secure and done with the best practices.