首页 > 解决方案 > 如何通过 SQL 将文本中的撇号发送到 DB2

问题描述

在 Zend Server 上,我们已经升级到 PHP 7,它破坏了一个 PHP 脚本。用户可以将文档中的文本粘贴到文本区域,然后通过 SQL 将其发送到 DB2 文件。在 PHP 7 之前,我使用它来确保发送撇号...

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

当然,这已被弃用,我将其替换为...

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

现在脚本只将文本发送到第一个带有撇号的单词。我已经玩了一段时间了,必须寻求帮助。建议?

我查看了 db2_prepared 语句,但仍然没有得到我要查找的撇号。正在使用的代码的更新...

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';
}

因此,如果用户在文本区域中输入 Andersons Farm,那么即使使用准备好的语句,DB2 文件中的最终结果也是 Andersons Farm。

标签: phppreg-replaceereg-replace

解决方案


推荐阅读