Just getting started with parameter binding and I've read all through the docs and quite a few questions/answers here, but I can't seem to get this to work.
Simply sorting via get request.
public function getAttributeGroups($data = array()) {
$params = array();
$sql = "
SELECT *
FROM {$this->db->prefix}attribute_group ag
LEFT JOIN {$this->db->prefix}attribute_group_description agd
ON (ag.attribute_group_id = agd.attribute_group_id)
WHERE agd.language_id = '" . (int)$this->config->get('config_language_id') . "'";
$sort_data = array(
'agd.name',
'ag.sort_order'
);
if (isset($data['sort']) && in_array($data['sort'], $sort_data)) {
//$sql .= " ORDER BY " . $data['sort'];
$sql .= " ORDER BY :sort";
$params[':sort'] = $data['sort'];
} else {
$sql .= " ORDER BY agd.name";
}
if (isset($data['order']) && ($data['order'] == 'DESC')) {
$sql .= " DESC";
} else {
$sql .= " ASC";
}
if (isset($data['start']) || isset($data['limit'])) {
if ($data['start'] < 0) {
$data['start'] = 0;
}
if ($data['limit'] < 1) {
$data['limit'] = 20;
}
$sql .= " LIMIT " . (int)$data['start'] . "," . (int)$data['limit'];
}
$query = $this->db->query($sql, $params);
return $query->rows;
}
The quoted line is the original that sorts just fine, but in analyzing the code is open to injections.
The above does execute a query and returns data, but it doesn't sort by the passed in binding.
What am I missing?