I have a question about this query, does codeigniter prevent SQL injection when we use this query:
$this->db->like();
$query = $this->db->get();
I have a question about this query, does codeigniter prevent SQL injection when we use this query:
$this->db->like();
$query = $this->db->get();
Despite lolipaps bad attitude may as well offer an answer that actually responds to this code.
First off, this will never work so the question of whether it prevents SQL injection is moot. In order to actually get anything back from this you would need to define both the like conditions and the table from which to perform the get. eg
$this->db->like('field','string');
$this->db->get('table');
Additionally it can never be vulnerable to SQL injection as in the example code (the code we are supposed to help support) there are no arguments passed. If the code was even close to being a viable real world example it might look like this
$some_input=$this->input->post('something_from_the_outside_world');
$this->db->like('field',$some_input); //maybe the question is whether this is sanitized??
$this->db->get('table');
If the question is whether this input is sanitized for SQL injection then the answer is yes of course it is or what's the point of the Active Record class.
If you want to further clean this for cross site scripting you either need to define this in the config.php file. eg
$config['global_xss_filtering'] = TRUE;
Or use the form validation library and run the rule xss_clean