I'm having issues binding ORDER BY and the direction in PDO. From what I've seen online, you need to bind SQL operators to the query but isn't that what I'm doing with my params
array? It seems that I'm doing everything properly here so I don't understand why it's not working.
/**
* Runs a query on the database
* @param mixed $params Array containing query and bind params
* @return mixex Raw database object
*/
public static function runQuery($params) {
// Prepare Query
$preparedQuery = Database::connection()->prepare($params["query"]);
// Execute Query
$preparedQuery->execute($params["params"]);
// Return results
return $preparedQuery;
}
/**
* Lists all values from a table
* @param string $table What table to query
* @return array Associative array from specific table with all values
*/
public static function getAll($table, $order, $direction) {
// List of results from database
$data = Utilities::runQuery([
"query" => "SELECT * from `$table` ORDER BY :order :direction",
"params" => [
":order" => $order,
":direction" => $direction
]
]);
// Return list
return $data->fetchAll(PDO::FETCH_ASSOC);
}