I understand that I should use prepared statements to prevent SQL injection. Unfortunately, having read the PHP docs on the matter I am none the wiser. Here is one of my simple active record SQL queries in a CI2 model, could someone show me an example of how I might turn this into a prepared statement - do I even need to?
function get_item($id){
$this->db
->select('*')
->from('item_entries')
->where('item_entries.item_id', $id)
->join('item_categories_rel', 'item_categories_rel.item_id = item_entries.item_id');
$query = $this->db->get();
if(is_object($query)){return $query->result_array();}else{return $query;}
}
Am I correct in thinking prepared statements are only necessary if I am accepting user data - if so lets assume $id
is user submitted. Although it is not, I am about to write some form to db statements, so advice in preparation for this is appreciated.
$this->db->where('col = ' . $value)
, you are safe. – Dan F. Sep 28 '12 at 16:26