Open Source RDBMS - Seamless, Scalable, Stable and Free

한국어 | Login |Register

Versions available for this page:

cubrid_real_escape_string

Description

The cubrid_real_escape_string function returns the escaped string version of the given string. Follow two escape sequence methods should be supported. On the quoted escape sequence, a string quoted with " or ' can be applied when system parameter ansi_quotes is set to "yes". If this option is set to "no", only a string quoted with ' can be applied. The default value is "no".

Quoted escape sequence:

  • A ' inside a string quoted with ' may be written as ' '
  • A " inside a string quoted with " may be written as "" (applied when ansi_quotes=yes)
  • A ' inside a string quoted with " needs no special treatment and need not be doubled or escaped. (applied when ansi_quotes=yes)
  • In the same way, " inside a string quoted with ' needs no special treatment.

Backslash escape sequence: This sequence is on by system parameter no_backslash_escapes.

The following characters can be escaped by backslash: \', \", \n, \r, \t, \\, \% \_.

If this option is set to "no", backslash escaping will work. The default value is "yes".

Syntax

string cubrid_real_escape_string (string $unescaped_string [, resource $link_identifier ] )

  • unescaped_string : The string that is to be escaped.
  • conn_identifier : The CUBRID connection. If the link identifier is not specified, the last link opened by cubrid_connect() is assumed.
Return Value
  • Success : Escaped characters
  • Failure : FALSE
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);

?>

 

The above example will output:

 

array(1) {

  ["t"]=>

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

}