title: Do backslashes escape quotes in mysql?
body: <p>Here's a var_dump of the query that is failing</p>
  
  <pre><code>string 'INSERT INTO event(name, description, location, image, datetime) VALUES('Nica\'s Weight Loss Class', 'Description goes here!', 'Location', 'Nica's Weight Loss Class.png', '2015-01-01T01:00')' (length=189)`
  </code></pre>
  
  <p>The error is </p>
  
  <blockquote>
    <p>You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 's Weight Loss Class.png', '2015-01-01T01:00')'</p>
  </blockquote>
  
  <p>And the line of code creating the query string is: (all variables escaped before-hand)</p>
  
  <pre><code>$query = "INSERT INTO event(name, description, location, ".($imageForEvent?"image, ":"")."datetime) VALUES('$evName', '$evDescription', '$evLocation', ".($imageForEvent?"'".basename($imageForEvent)."', ":"")."'$evDatetime')";
  </code></pre>
  
  <p>According to the <a href="https://dev.mysql.com/doc/refman/5.0/en/string-literals.html" rel="nofollow noreferrer" title="mysql docs">mysql docs</a> a backslash character is used to escape single quotes. </p>
  
  <p>However, according <a href="https://stackoverflow.com/questions/9596652/how-to-escape-apostrophe-in-mysql">How to escape apostrophe (&#39;) in MySql?</a>, the correct way seems to be to double the quotation mark.</p>
  
  <p>I've tested both ways and they give the same error in the same place. Can anyone shed some light on this subject?</p>