I am new to PDO and am creating a class. I want to make the code as clean as possible and have a few pages as possible. I am planning on sending the column and table names in as a parameter:
function get($column, $table, $where) {
global $db;
$query = 'SELECT '.$column.' FROM '.$table.' WHERE '.$where.'';
try {
$statement = $db->prepare($query);
$statement->execute();
$result = $statement->fetchAll();
$statement->closeCursor();
return $result;
} catch (PDOException $e) {
$error_message = $e->getMessage();
display_db_error($error_message);
}
}
It works fine, but I am wondering how safe it would be considered.