cubrid_real_escape_string

(PECL CUBRID >= 8.3.0)

cubrid_real_escape_stringEscape special characters in a string for use in an SQL statement

说明

cubrid_real_escape_string ( string $unescaped_string [, resource $conn_identifier ] ) : string

This function returns the escaped string version of the given string. It will escape the following characters: '. In general, single quotations are used to enclose character string. Double quotations may be used as well depending on the value of ansi_quotes, which is a parameter related to SQL statement. If the ansi_quotes value is set to no, character string enclosed by double quotations is handled as character string, not as an identifier. The default value is yes. If you want to include a single quote as part of a character string, enter two single quotes in a row.

参数

unescaped_string

The string that is to be escaped.

conn_identifier

The CUBRID connection. If the connection identifier is not specified, the last connection opened by cubrid_connect() is assumed.

返回值

Escaped string version of the given string, on success.

FALSE on failure.

范例

Example #1 cubrid_real_escape_string() example

<?php
$conn 
cubrid_connect("localhost"33000"demodb");

$unescaped_str ' !"#$%&\'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~';
$escaped_str cubrid_real_escape_string($unescaped_str);

$len strlen($unescaped_str);

@
cubrid_execute($conn"DROP TABLE cubrid_test");
cubrid_execute($conn"CREATE TABLE cubrid_test (t char($len))");
cubrid_execute($conn"INSERT INTO cubrid_test (t) VALUES('$escaped_str')");

$req cubrid_execute($conn"SELECT * FROM cubrid_test");
$row cubrid_fetch_assoc($req);

var_dump($row);

cubrid_close_request($req);
cubrid_disconnect($conn);
?>

以上例程会输出:

array(1) {
  ["t"]=>
  string(95) " !"#$%&'()*+,-./0123456789:;<=>?@ABCDEFGHIJKLMNOPQRSTUVWXYZ[\]^_`abcdefghijklmnopqrstuvwxyz{|}~"
}
相关文章
php cubrid cubrid mysql 兼容性函数php cubrid mysql 兼容性函数 return the number of rows affected by the last sql statementphp cubrid mysql 兼容性函数 move the internal row pointer of the cubrid resultphp cubrid mysql 兼容性函数 get the error messagephp cubrid 函数 execute a prepared sql statementphp cubrid mysql 兼容性函数 fetch a result row as an associative array a numeric array or bothphp cubrid mysql 兼容性函数 return the associative array that corresponds to the fetched rowphp cubrid mysql 兼容性函数 get column information from a result and return as an objectphp cubrid mysql 兼容性函数 return an array with the lengths of the values of each field from the current rowphp cubrid mysql 兼容性函数 fetch the next row and return it as an objectphp cubrid mysql 兼容性函数 return a numerical array with the values of the current rowphp cubrid mysql 兼容性函数 return a string with the flags of the given field offsetphp cubrid 函数 bind a lob object or a string as a lob object to a prepared statement as parametersphp cubrid mysql 兼容性函数 return the number of columns in the result setphp cubrid mysql 兼容性函数 ping a server connection or reconnect if there is no connectionphp cubrid mysql 兼容性函数 escape special characters in a string for use in an sql statementphp dbx 函数 escape a string so it can safely be used in an sql statementphp ingres 函数 escape special characters for use in a queryphp maxdb 函数 escapes special characters in a string for use in an sql statement taking into account the current charset of the connectionphp mysqlnduhconnection escapes special characters in a string for use in an sql statement taking into account the current charset of the connection
关注编程学问公众号