title: How to send apostrophes within text to DB2 via SQL
body: <p>On Zend Server we have upgraded to PHP 7 which has broken a PHP script. A user is able to paste text from a document into a text area which then is sent to a DB2 file via SQL. Prior to PHP 7 I was using this to make sure the apostrophes were being sent...</p>
  
  <pre><code>$lineout = ereg_replace("'", "''", $line[$a]);
  </code></pre>
  
  <p>Of course this has been deprecated and I replaced it with...</p>
  
  <pre><code>$lineout = preg_replace("/'/", "/''/", $line[$a]);
  </code></pre>
  
  <p>Now the script only sends text up to the first word that has an apostrophe. I have been playing with this for awhile and must seek help. Suggestions?</p>
  
  <p>I have looked into the db2_prepared statement and I am still not getting the apostrophes I am looking for. An update to the code being used...</p>
  
  <pre><code>if ($b &lt; 999) {
      $conn = db2_connect($_SESSION['i5'] , decode($_SESSION['def_user'], 
              $_SESSION['key']), decode($_SESSION['def_pwd'], $_SESSION['key']), 
              array(i5_lib=&gt;$_SESSION['lib']));
      if (!$conn) { echo 'bad';
          die(i5_errormsg());
      } 
      $query = "delete from tmpdesc where deprcl = '$parcel'";
      $stmt = db2_exec($conn, $query);
  
      for ($a = 0; $a &lt;= $b; $a++) {
          $query = "insert into tmpdesc (deprcl, derecn, dedesc) values('$parcel', 
                   $a+1, '$line[$a]')";
          $prepared_query = db2_prepare($conn, $query);
          $stmt = db2_exec($conn, $prepared_query);
          if (!$stmt) {
              echo 'Error during query insertion&lt;br/&gt;Code: ' . i5_errno($conn) 
                   . '&lt;br/&gt;';
              echo 'Message: ' . i5_errormsg($conn) . '&lt;br/&gt;';
          }
      }
      echo '&lt;p&gt;&lt;br/&gt;Legal descriptions have been sent.&lt;/p&gt;';
      return '0';
  } else {
      echo '&lt;font color=red&gt;You have ', $b, ' lines of descriptions which is 
           more than the 999 allowed.&lt;/font&gt;';
      return '1';
  }
  </code></pre>
  
  <p>So if a user enters Anderson's Farm in the text area what ends up in the DB2 file is Andersons Farm even with the prepared statement.</p>