db2_escape_string

(PECL ibm_db2 >= 1.6.0)

db2_escape_string Used to escape certain characters

说明

db2_escape_string ( string $string_literal ) : string

Prepends backslashes to special characters in the string argument.

参数

string_literal

The string that contains special characters that need to be modified. Characters that are prepended with a backslash are \x00, \n, \r, \, ', " and \x1a.

返回值

Returns string_literal with the special characters noted above prepended with backslashes.

范例

Example #1 A db2_escape_string() example

Result of using the db2_escape_string() function

<?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:

参见

相关文章
php ibm db2 函数 returns or sets the autocommit state for a database connectionphp ibm db2 函数 binds a php variable to an sql statement parameterphp ibm db2 函数 returns an object with properties that describe the db2 database clientphp ibm db2 函数 closes a database connectionphp ibm db2 函数 returns a result set listing the columns and associated privileges for a tablephp ibm db2 函数 returns the cursor type used by a statement resourcephp ibm db2 函数 used to escape certain charactersphp ibm db2 函数 returns an array indexed by both column name and position representing a row in a result setphp ibm db2 函数 returns an object with properties representing columns in the fetched rowphp ibm db2 函数 sets the result set pointer to the next row or requested rowphp ibm db2 函数 returns the maximum number of bytes required to display a columnphp ibm db2 函数 returns the name of the column in the result setphp ibm db2 函数 requests the next result set from a stored procedurephp ibm db2 函数 returns the number of fields contained in a result setphp ibm db2 函数 returns the number of rows affected by an sql statementphp ibm db2 函数 closes a persistent database connectionphp ibm db2 函数 returns a string containing the last sql statement error messagephp ibm db2 函数 returns a result set listing the tables and associated privileges in a databasephp ibm db2 函数 returns a result set listing the tables and associated metadata in a databasephp dbx 函数 escape a string so it can safely be used in an sql statement
关注编程学问公众号