title: How to escape single quote in laravel Raw query
body: <p>Previously, I was inserting data from csv to database using eloquent. However, I feel this quite slow, so I am trying to test it with Raw Query as follows in laravel:</p>
  
  <pre><code>$query = Committee::where('name', $committee_arr['name']);
  
  if ($committee_arr['mailing_address_city']) {
      $query-&gt;where('mailing_address_city', $committee_arr['mailing_address_city']);
  }
  if ($committee_arr['mailing_address_state']) {
      $query-&gt;where('mailing_address_state', $committee_arr['mailing_address_state']);
  }
  if ($committee_arr['mailing_address_zip']) {
      $query-&gt;where('mailing_address_zip', $committee_arr['mailing_address_zip']);
  }
  
  $committee = $query-&gt;first();
  
  if ($committee) {
      $committee_arr['updated_at'] = date('Y-m-d H:i:s');
      $committee_arr['updated_by'] = $this-&gt;data['user_id'];
      try {
          $valueSets = array();
          foreach ($committee_arr as $k =&gt; $v) {
              $valueSets[] = $k . " = '" . $v . "'";
          }
          DB::update("Update `fec` set " . implode(", ", $valueSets) . " where id = " . $committee-&gt;id);
          $committee_id = $committee-&gt;id;
      } catch (\Exception $e) {
          $error_encountered = true;
          $this-&gt;error_arr[] = $e-&gt;getMessage();
          $this-&gt;error_row_numbers[] = $this-&gt;data['row_value'];
      }
  
  } else {
      $committee_arr['created_at'] = date('Y-m-d H:i:s');
      $committee_arr['created_by'] = $this-&gt;data['user_id'];
      try {
          $columns = implode(", ", array_keys($committee_arr));
          $values = "'" . implode("', '", array_values($committee_arr)) . "'";
          DB::insert("INSERT INTO `fec`($columns) VALUES ($values)");
          $committee_id = DB::getPdo()-&gt;lastInsertId();
      } catch (\Exception $e) {
          $error_encountered = true;
          $this-&gt;error_arr[] = $e-&gt;getMessage();
          $this-&gt;error_row_numbers[] = $this-&gt;data['row_value'];
          DB::rollback();
      }
  
  }
  </code></pre>
  
  <p>However, in this process I encounter one problem of these single quotes. I don't know how to use <code>mysqli_real_escape_string</code> in Laravel. I have also noticed about <code>addslashes</code> but I don't feel it's the ideal way. </p>
  
  <p>So, is there any way to deal with this? Further more if you have any idea of inserting with something like parameter binding then you are welcome.</p>
  
  <p>If you wonder what does that <code>$committee_arr</code> contains then it looks like below:</p>
  
  <pre><code>Array
  (
      [name] =&gt; O'KANE, PATRICK M
      [mailing_address_city] =&gt; SAN ANTONIO
      [mailing_address_state] =&gt; TX
      [mailing_address_zip] =&gt; 782583940
      [employer] =&gt; ENERGY TRANSFER EMPLEE MGMT CO
      [occupation] =&gt; SR DIRECTOR - PL HEDGNG/COMMOD
  )
  </code></pre>
  
  <h2>Futher Clarification:</h2>
  
  <p>My main concern is to handle <code>O'Kane</code> properly. But, if I have to say it exactly, then I want to handle with something like below. But, the problem with it is that, these fields and value are totally dynamic. It will be in array as shown above. Not limiting to above six fields and values, there may be more than that as well.</p>
  
  <pre><code>$results = DB::select( DB::raw("SELECT * FROM some_table WHERE some_col = :somevariable"), array(
     'somevariable' =&gt; $someVariable,
   ));
  </code></pre>