title: Escaping SQL queries in Codeigniter
body: <p>I am inserting some data into a MySQL table using CodeIgniter. Because I am using <code>INSERT IGNORE INTO</code> and do not want to edit the active records class to enable this feature, I am generating the SQL query manually.</p>
  
  <pre><code>$this-&gt;db-&gt;query("INSERT IGNORE INTO my_table(lat, lng, date, type)
                          VALUES ('" . $data['lat'] . "', '" . $data['lng'] . "', '" . $data['date'] . "', '" . $data['type'] . "')");
  </code></pre>
  
  <p><strong>Problem:</strong> The query failed when the string in <code>$data['type']</code> contained a single quote. How can I make it such that these characters that need to be escaped gets escaped automatically, like when using Active records?</p>