PHP8 db2_escape_string

2024-04-07 10:22 更新

(PECL ibm_db2 >= 1.6.0)

db2_escape_string — 用于转义某些字符

说明

db2_escape_string(string $string_literal): string

在字符串参数中将反斜杠预置到特殊字符。

参数 

string_literal

包含需要修改的特殊字符的字符串。 前面加上反斜杠的字符是 、 、 、 、 和 。\x00\n\r\'"\x1a

返回值 

返回特殊字符 如上所述,前面加上反斜杠。string_literal

示例 

示例 #1 A db2_escape_string() example

使用 db2_escape_string() 函数的结果

<?php

$conn = db2_connect($database, $user, $password);

if ($conn) {
    $str[0] = "All characters: \x00 , \n , \r , \ , ' , \" , \x1a .";
    $str[1] = "Backslash (\). Single quote ('). Double quote (\")";
    $str[2] = "The NULL character \0 must be quoted as well";
    $str[3] = "Intersting characters: \x1a , \x00 .";
    $str[4] = "Nothing to quote";
    $str[5] = 200676;
    $str[6] = "";

    foreach( $str as $string ) {
        echo "db2_escape_string: " . db2_escape_string($string). "\n";
    }
}
?>

以上示例会输出:

db2_escape_string: All characters: \0 , \n , \r , \\ , \' , \" , \Z .
db2_escape_string: Backslash (\\). Single quote (\'). Double quote (\")
db2_escape_string: The NULL character \0 must be quoted as well
db2_escape_string: Intersting characters: \Z , \0 .
db2_escape_string: Nothing to quote
db2_escape_string: 200676
db2_escape_string:

参见 

  • db2_prepare() - 准备要执行的 SQL 语句


以上内容是否对您有帮助:
在线笔记
App下载
App下载

扫描二维码

下载编程狮App

公众号
微信公众号

编程狮公众号