Jump to content

Recommended Posts

That is sort of correct folks, however it isn't really for 'security purposes'.  It is called character escaping, and it is done so that MySQL knows where your query actually begins and ends.

 

Example:

<?php mysql_query("SELECT * FROM tbl WHERE name='bob's tackle'"); ?>

 

Without character escaping MySQL would think the query is SELECT * FROM tbl WHERE name='bob ... because what we view as an apostrophe to denote a plural tense, MySql sees as the closing apostrophe to the name condition.

 

So the above example should be:

<?php mysql_query("SELECT * FROM tbl WHERE name='bob\'s tackle'"); ?>

 

Prior to inserting data into MySQL tables you should use something like mysql_real_escape_string() (for non integer data). You generally won't need to 'strip slashes' if you use mysql_real_escape_string.

 

Character escaping goes well beyond PHP and MySQL ... it's done in nearly every syntax.

 

If you ever feel so inclined, you can trace the lineage of character escaping back to regular expressions.

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.