views:

28

answers:

3

I was wondering if when using the database library in Codeigniter there was a way to automatically escape all the inputs to prevent injection. I know I can use mysql_real_escape_string() to do it, but I wondered it this was already setup to do this automatically, if not are there any frameworks that have this included?

Thanks!

+1  A: 

Right, pretty much all frameworks that implement any sort of database abstraction/ORM layer will automatically mysql_real_espace your queries. If you don't want to use an entire framework, consider a generic ORM library like Propel or Doctrine. Alternatively, look into prepared statements.

deceze
Thank you for your response, with a default installation of CodeIgniter, I added in the database library and I can insert quotes into a text input which then is sent to an Update query (using the database helper) and it results in a syntax error. So perhaps there is further configuration with CodeIgniter?
Pete Herbert Penito
@Pete Sorry, I don't understand what you're asking. From your question I thought you were already familiar with CodeIgniter and are looking for ORM libraries like the one CI uses, which *doesn't* require any manual escaping...? Personally I have no experience with CI, so I can't tell you any specifics about it.
deceze
+1  A: 

CakePHP runs all model queries through its own methods, if you use the model methods it automatically sanitizes any data passed to the query for you. i.e

$options['conditions'] = array('Product.status'=>$status);
$this->Product->find('first',$options);
woodscreative
+2  A: 

In order to use prepared statements, you can simply use query bindings with CodeIgniter.

$query = 'SELECT id, name FROM user WHERE name = ?';
$bind = array('Jake');
$this->db->query($query, $bind);

More info found here.

akira_x