We use cookies to improve your experience. No personal information is gathered and we don't serve ads. Cookies Policy.

ExpressionEngine Logo ExpressionEngine
Features Pricing Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University
Log In or Sign Up
Log In Sign Up
ExpressionEngine Logo
Features Pro new Support Find A Developer
Partners Upgrades
Blog Add-Ons Learn
Docs Forums University Blog
  • Home
  • Forums

Is mysql_real_escape_string needed when using active record queries?

Development and Programming

vosSavant's avatar
vosSavant
380 posts
14 years ago
vosSavant's avatar vosSavant

Maybe a dumb question, but…do I need to run mysql_real_escape_string on user input before running it through something like:

$data = array(
   'group_id'     => 7,
   'username'     => '',
   'screen_name'  => $author
);

$this->EE->db->insert ( 'exp_members', $data );

I believe Active Record already escapes data, but I wasn’t able to find a definitive answer. I ask because I’m running mysql_real_escape_string on $author, and I end up with slashes before single quotes.

Thanks, a fried mind greatly appreciates it.

Edit: I just realized this might not be the best forum for my question. Apologies in advance. :shut:

Moved to Development and Programming by Moderator

       
Sue Crocker's avatar
Sue Crocker
26,054 posts
14 years ago
Sue Crocker's avatar Sue Crocker

Hi, Ryan. Let me move this for you to the Developer forum. 😊

       
vosSavant's avatar
vosSavant
380 posts
14 years ago
vosSavant's avatar vosSavant

Hi Sue,

With a refreshed mind, I was able to find an answer. From the user guide:

Beyond simplicity, a major benefit to using the Active Record features is that it allows you to create database independent applications, since the query syntax is generated by each database adapter. It also allows for safer queries, since the values are escaped automatically by the system.

So, it is not necessary to use mysql_real_escape_string with AR queries, since you’ll double escape data.

       

Reply

Sign In To Reply

ExpressionEngine Home Features Pro Contact Version Support
Learn Docs University Forums
Resources Support Add-Ons Partners Blog
Privacy Terms Trademark Use License

Packet Tide owns and develops ExpressionEngine. © Packet Tide, All Rights Reserved.