Gregg Willow
Gregg Willow

Reputation: 1

How to send apostrophes within text to DB2 via SQL

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...

$lineout = ereg_replace("'", "''", $line[$a]);

Of course this has been deprecated and I replaced it with...

$lineout = preg_replace("/'/", "/''/", $line[$a]);

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?

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...

if ($b < 999) {
    $conn = db2_connect($_SESSION['i5'] , decode($_SESSION['def_user'], 
            $_SESSION['key']), decode($_SESSION['def_pwd'], $_SESSION['key']), 
            array(i5_lib=>$_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 <= $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<br/>Code: ' . i5_errno($conn) 
                 . '<br/>';
            echo 'Message: ' . i5_errormsg($conn) . '<br/>';
        }
    }
    echo '<p><br/>Legal descriptions have been sent.</p>';
    return '0';
} else {
    echo '<font color=red>You have ', $b, ' lines of descriptions which is 
         more than the 999 allowed.</font>';
    return '1';
}

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.

Upvotes: 0

Views: 86

Answers (0)

Related Questions