PHP8 db2_escape_string

2024-04-07 10:22 更新

(PECL ibm_db2 >= 1.6.0)

db2_escape_string — 用于轉(zhuǎn)義某些字符

說明

db2_escape_string(string $string_literal): string

在字符串參數(shù)中將反斜杠預(yù)置到特殊字符。

參數(shù) 

string_literal

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

返回值 

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

示例 

示例 #1 A db2_escape_string() example

使用 db2_escape_string() 函數(shù)的結(jié)果

<?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() - 準(zhǔn)備要執(zhí)行的 SQL 語句


以上內(nèi)容是否對您有幫助:
在線筆記
App下載
App下載

掃描二維碼

下載編程獅App

公眾號
微信公眾號

編程獅公眾號